Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Forked from lucapette/toys.rb
Created February 18, 2012 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proudlygeek/1859417 to your computer and use it in GitHub Desktop.
Save proudlygeek/1859417 to your computer and use it in GitHub Desktop.
methods to create toys arrays and hashes (using modules)
module MonkeyIrb
def self.included(base)
# Monkey-patching Array
class << Array
def toy(n=10, &block)
block_given? ? Array.new(n, &block): Array.new(n) { |i| i + 1 }
end
end
# Monkey-patching Hash
class << Hash
def toy(n=10)
Hash[Array.toy(n).zip(Array.toy(n) {|c| (97 + c).chr})]
end
end
end
end
# Loading Monkey-patch module
include MonkeyIrb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment