From: dblack@... Date: 2007-09-03T19:24:01+09:00 Subject: Re: assigning to hash keys when there is a default value? Hi -- On Mon, 3 Sep 2007, 7stud -- wrote: > unknown wrote: >> x ||= y is, I think, always supposed to be exactly equivalent to >> x = x || y, so that line in your first hash should be equivalent to: >> >> h[2] = 5 || 10 >> >> which should assign 5 to h[2]. It looks to me like you've found a bug. >> I can't think of any reason (and I really hope there isn't one, >> because having an exception to that ||= rule would be very messy) why >> using a default hash value would make any difference here. It's still >> 5 || 10 on the rhs, and it's still just an assignment. > > I don't think it's a bug; the two examples are set forth on p. 276 of > "The Ruby Way (2nd ed)". However, no explanation is given for why the > two examples work differently. It seems very bug-like to me. I don't know what Hal's take on it is. Paging Hal.... David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)