Hi,
In message "Re: ||=3D with 1.8 and 1.9 ?"
=A0 =A0on Thu, 27 Aug 2009 01:20:20 +0900, Rick DeNatale <rick.denatale@g=
mail.com said:
|a =3D b =3D c
|
| is treated the same as
|
|b =3D c; a =3D c
|
|in other words the result of the b=3D is ignored.
No,
=A0a =3D b =3D c
is parsed as
=A0a =3D (b =3D c)
Yes, I was speaking a bit loosely and was trying to say just what you said =
next
so, result of the latter assignment is used for the former assignment.
The point is when b here is an attribute assignment (e.g. foo.b =3D c),
the result value from the setter method (b=3D) is ignored.
And I think that the really important point here is that
a.b ||=3D c
should have have the same effect as
a.b || a.b =3D c
And that it's surprising that in Ruby 1.9 it doesn't
puts RUBY_VERSION
class OrOrEquals
def test
@test
end
def test=3D(test)
@test =3D test
'not test'
end
end
o =3D OrOrEquals.new
direct =3D o.test =3D 'a test'
p direct
o.test =3D nil
with_oror =3D o.test ||=3D 'a test'
p with_oror
with_or_or_assign =3D o.test || o.test =3D "a test"
p with_or_or_assign
$ multiruby or_or_equals.rb
/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:144:
warning: /Users/rick/.gem/ruby/1.8/specifications: Permission denied
VERSION =3D 1.8.6-p368
CMD =3D ~/.multiruby/install/1.8.6-p368/bin/ruby or_or_equals.rb
1.8.6
"a test"
"a test"
"a test"
RESULT =3D 0
VERSION =3D 1.8.7-p160
CMD =3D ~/.multiruby/install/1.8.7-p160/bin/ruby or_or_equals.rb
1.8.7
"a test"
"a test"
"a test"
RESULT =3D 0
VERSION =3D 1.9.1-p0
CMD =3D ~/.multiruby/install/1.9.1-p0/bin/ruby or_or_equals.rb
1.9.1
"a test"
"not test"
"a test"
RESULT =3D 0
--=20
Rick DeNatale
Blog:
http://talklikeaduck.denhaven2.com/
Twitter:
http://twitter.com/RickDeNatale
WWR:
http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn:
http://www.linkedin.com/in/rickdenatale