Created
February 2, 2011 10:08
-
-
Save lucapette/807492 to your computer and use it in GitHub Desktop.
methods to create toys arrays and hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def self.toy(n=10, &block) | |
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1} | |
end | |
end | |
class Hash | |
def self.toy(n=10) | |
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})] | |
end | |
end |
Yep very very nice I think i'll steal them :)
Well then we are even since I stole your idea for my .irbrc :-)
:D perfect!
good idea! thanks!
glad you like it :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I followed this from stack overflow.
Why not just extend the classes?
then when you need a toy hash or array to play with in irb you can just:
Hash.toy
Array.toy
Seems a little more rubyesque? No?