From: Christopher Dicely Date: 2009-03-07T13:07:25+09:00 Subject: Re: Extending has for default value, can't get it to work On Fri, Mar 6, 2009 at 7:22 PM, Jo Be wrote: > http://pastie.org/409974 > > When I instantiate MyHash.new I get an empty hash. Just not sure how to > proceed. > > thanks ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mswin32] irb(main):001:0> class MyHash < Hash irb(main):002:1> def initialize irb(main):003:2> super irb(main):004:2> self[:foo]="bar" irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> MyHash.new => {:foo=>"bar"} Actually, I tried it your way out of curiosity, and: irb(main):009:0> class MyOtherHash < Hash irb(main):010:1> def initialize irb(main):011:2> super irb(main):012:2> merge!({:foo=>"bar"}) irb(main):013:2> end irb(main):014:1> end => nil irb(main):015:0> MyOtherHash.new => {:foo=>"bar"}