From: "David A. Black" Date: 2008-05-02T07:10:56+09:00 Subject: Re: Please explain nuances of ||= Hi -- On Fri, 2 May 2008, Phillip Gawlowski wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > David A. Black wrote: > | Hi -- > | > | On Fri, 2 May 2008, Phillip Gawlowski wrote: > | > | Whoops -- sorry :-) > > As if. :P > > | I actually have a feeling we're talking at cross-purposes, and that > | I'm somehow not getting something. All I'm saying is that h[x] ||= > | value is the same as h[x] || h[x] = value, for any hash h and any key > | x. That can be demonstrated easily (as Robert did) just by > | substituting one expression for the other. It's an unusual case, but > | it's legal. I'm not sure what would be needed beyond that to > | demonstrate that x = x || y is not a drop-in replacement for x ||= y. > > Yeah, I'm taking the Bird's Eye View on it all, essentially saying: 'it > works like this almost always, but Hash is a special case, since it has > default values [or whatever the implementation detail is, that makes > Hash work differently]). It's possible to generalize it; someone in one of the threads wrote a class that showed the same behavior, but I can't remember the details. I do wish it were otherwise; it's definitely unexpected, I think. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!