Created
June 5, 2013 12:20
-
-
Save ivopt/5713497 to your computer and use it in GitHub Desktop.
A few augmentations to Ruby Hash..
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 Hash | |
def self.infinite | |
self.new{|h, k| h[k] = self.new(&h.default_proc)} | |
end | |
def self.recursive max = nil | |
if max && max.kind_of?(Fixnum) | |
self.new{|h,k| h[k] = self.recursive(max-1) if max > 1} | |
else | |
infinite | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment