bob != the greatest

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

Advertisements

Leave a comment

Filed under Ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s