Sha256: a1a3e60417fea28706b5a822eecd9474dff6e04d8f88c4e156d8c61ade3a8d94

Contents?: true

Size: 593 Bytes

Versions: 7

Compression:

Stored size: 593 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 any results
  #
  # @example Generate an array of three random numbers
  #   3.maps{rand}
  #   => [0.0248131784304143, 0.814666170190905, 0.15812816258206]
  #
  
  def maps
    return (0...self).map{|item| yield item}
  end


end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sixarm_ruby_ramp-4.2.3 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.2.2 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.1.0 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-4.0.0 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-3.0.0 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-2.1.3 lib/sixarm_ruby_ramp/integer.rb
sixarm_ruby_ramp-2.1.0 lib/sixarm_ruby_ramp/integer.rb