Created
June 30, 2010 20:34
-
-
Save hukl/459185 to your computer and use it in GitHub Desktop.
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 CrazyHash < Hash | |
def initialize init_hash | |
super.merge! init_hash | |
end | |
def to_s | |
"do something different and important so the literal {} wont work" | |
end | |
end | |
f = CrazyHash.new( :b => "C" ) | |
puts f.inspect | |
=> {:b=>"C"} |
Hmm, I don't get it. What's the point?
@handtwerk that you can't say Hash.new( :foo => "bar" )
by overloading #initialize that way - you can. and that you can overload it that easy is just awesome - at least to me
so named paramters type functionality...
@plukevdh - could you elaborate ? ;)
I see, that's neat. Go Ruby!
@hukl kinda like what Obj-C has.
Uhm yeah - rubyists use hashes for named arguments all the time but in this gist it is not the point ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
well CrazyHash has other methods. Its really a customized Hash so the literal won't work