Sha256: fb30c1a7e060d040a8745b7c3d6aa293a94aa5211764a25b0425321f8549ea43

Contents?: true

Size: 677 Bytes

Versions: 6

Compression:

Stored size: 677 Bytes

Contents

# -*- coding: utf-8 -*-

# Integer extensions

class Integer

  # Syntactic sugar to yield n times to a block.
  #
  # ## Comparison to Integer#times
  #
  # Integer#maps is similar to Integer#times except that the output from each
  # call to the block is captured in an array element and that array is
  # returned to the calling code.
  #
  # @return an array of results
  #
  # @example Generate an array of three random numbers
  #   3.maps{rand}
  #   => [0.0248131784304143, 0.814666170190905, 0.15812816258206]
  #
  # @example Multiply the current index
  #   3.maps{|i| i * 2}
  #   => [0, 2, 4]
  #
  def maps
    return (0...self).map{|item| yield item}
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sixarm_ruby_ramp-5.0.2 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-5.0.1 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-5.0.0 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.2.7 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.2.5 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.2.4 lib/sixarm_ruby_ramp/integer.rb