Fun bug. It’s not all that hard to see once you sort out what line it’s on, but when the sauce is much thicker… the initial Hash definition may not be the first place you check.
…and when I say “you”, I of course mean “me”. It may not be the first place me check.
>> a = Hash.new{ |h,k| h[k] = 1; bob = "lame" }
=> {}
>> a[0]
=> "lame"
>> a[0]
=> 1
>> a = Hash.new{ |h,k| bob = "the greatest"; h[k] = 1 }
=> {}
>> a[0]
=> 1
>> a[0]
=> 1
Advertisement