Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/sixarm_ruby_integer_map/integer/map.rb

Overview

Please see README

Instance Method Summary collapse

Instance Method Details

#mapObject

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.

Examples:

Generate an array of three random numbers

3.map{rand}
=> [0.0248131784304143, 0.814666170190905, 0.15812816258206]

Multiply the current index

3.map{|i| i * 2}
=> [0, 2, 4]

Returns:

  • an array of results



26
27
28
# File 'lib/sixarm_ruby_integer_map/integer/map.rb', line 26

def map
  self.times.map{|i| yield i}
end