From: Yukihiro Matsumoto Date: 2006-09-25T13:08:59+09:00 Subject: Re: Behavior change for Hash#default in 1.8.5? Hi, In message "Re: Behavior change for Hash#default in 1.8.5?" on Mon, 25 Sep 2006 12:33:02 +0900, Daniel Berger writes: |It appears that something has changed with Hash#default between 1.8.4 |and 1.8.5: Yes. |irb(main):001:0> VERSION |=> "1.8.4" |irb(main):002:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default |=> 0 Under pre 1.8.5 versions, #default method erroneously calculate the default value. In above example, the block was called with k=nil, so that the value of 0 was returned. 1.8.5 fixed this, so that #default returns nil that indicates it has no default value set. If you want to know the value for the specific key, invoke #default with key argument specified |irb(main):001:0> VERSION |=> "1.8.5" |irb(main):002:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default |=> nil irb(main):003:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default(3) => 9 matz.