Skip to content

Instantly share code, notes, and snippets.

@maletor
Last active December 21, 2015 19:49
Show Gist options
  • Save maletor/6356577 to your computer and use it in GitHub Desktop.
Save maletor/6356577 to your computer and use it in GitHub Desktop.
class Integer
# Public: Return n number of somthing as Array.
#
# Examples
#
# foot = 5.of { Toe.new } # => [<toe>, <toe>, <toe>, <toe>, <toe>]
# feet = Array.new(5) { Toe.new } # => [<toe>, <toe>, <toe>, <toe>, <toe>]
#
def of
(0..self-1).map { |n| yield n }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment