From: "Peña, Botp" Date: 2007-07-04T17:24:56+09:00 Subject: Re: Isn't hash default value behavior just a little bizarre? On Behalf Of Farhad Farzaneh: # Still, I do find it pretty surprising. I got stung when I # was actually # using the feature to initialize any entry to an array just to # avoid the # business of # # hash[key] ||= [] just be careful w hash#[]<< method (but not too careful, otherwise, you would not enjoy ruby :). What you really wanted then was hash#[]= irb(main):041:0> y = Hash.new => {} irb(main):043:0> y[1] => nil irb(main):044:0> y[1] << "test" NoMethodError: undefined method `<<' for nil:NilClass from (irb):44 from :0 here, since y.default == nil or y[1] == nil, we are actually doing nil << "test" wc is obviously wrong. irb(main):045:0> y[1] = "test" => "test" take a look also at hash#default