Sha256: fbc8ef1b7e4128e4d969092f513fc8bad261b0a711c9c09a916e0fdff8e72446

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

# -*- coding: utf-8 -*-
=begin rdoc
Please see README
=end

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.map{rand}
  #   => [0.0248131784304143, 0.814666170190905, 0.15812816258206]
  #
  # @example Multiply the current index
  #   3.map{|i| i * 2}
  #   => [0, 2, 4]
  #
  def map
    self.times.map{|i| yield i}
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sixarm_ruby_integer_map-2.0.0 lib/sixarm_ruby_integer_map/integer/map.rb