From: Morton Goldberg Date: 2007-09-03T21:34:46+09:00 Subject: Re: assigning to hash keys when there is a default value? On Sep 3, 2007, at 7:37 AM, dblack@wobblini.net wrote: > The only possible explanation I can come up with, which I don't like, > is that: > > h[2] ||= 10 > > is being treated like: > > 5 = 5 || 10 > > which is just another can of worms. I don't want to believe that because it raises the question of why h[2] = 10 isn't treated as 5 = 10 I mean, I simply can't believe the Ruby interpreter would treat h[2] as a simple rvalue in h[2] ||= 10. Robert Klemme explanation is more believable although I find it somewhat upsetting after years of believing x = y is just syntactic sugar for x = x y. The optimization he describes is a plausible one, and I can't think of any other case where it would backfire. Regards, Morton