From: Phillip Gawlowski Date: 2008-05-02T05:37:50+09:00 Subject: Re: Please explain nuances of ||= -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David A. Black wrote: |> No, it means: x = x || y | | This is becoming a bit of a perma-thread :-) | | See Robert K.'s answer, and also have a look at the blog post I | mentioned in my response. It's about exactly why x = x || y is not the | right expansion for x ||= y. x ||= y expands into x = x || y, since x == 1 expands to x = x + 1, and we have no reason to expect ||= to behave differently (MPLOS). Also, it works as expected if the expansion x = x || y is correct. After all: 'The or and || operators evaluate their first operand. If true, the expression returns the value of their first operand; otherwise, the expression returns the value of the second operand.' Programming Ruby, 2nd Edition (p. 326). And Robert's answer works the way it works because the Hash has a default value set, which doesn't equate to false or nil. If you override the default value by setting the value to false, the assignment works again as expected. - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan Blog: http://justarubyist.blogspot.com Zero raised to the nth power remains zero. ~ -- Pop Baslim -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgaKhoACgkQbtAgaoJTgL/LkgCeMqByMe50+mJx/j8vV3KC612p lF4AnAz+GVlTLKNPdcjZnsFbbTTwHebv =Tkje -----END PGP SIGNATURE-----