From: Brian Candler Date: 2009-08-27T02:50:06+09:00 Subject: Re: ||= with 1.8 and 1.9 ? 7stud -- wrote: > Rick Denatale wrote: >>> a1 = A.new >>> puts a1.x = 10 >>> >>> a2 = A.new >>> puts a2.x=(10) >> >>> both versions return the same thing. >> >> Because they are both using the assignment sugar. Parenthesizing the >> 10 doesn't change that. > > The method name is 'x=' and it was called using 'obj.x='. Where's the > sugar? The parentheses in (10) are not delimiting arguments of a method call; they are just bracketing a value expression. Note: >> class Foo; def bar=(x,y,z); 123; end; end => nil >> Foo.new.send(:bar=,7,8,9) => 123 >> Foo.new.bar=(7,8,9) SyntaxError: compile error (irb):3: syntax error, unexpected ',', expecting ')' Foo.new.bar=(7,8,9) ^ from (irb):3 from :0 >> Similarly: >> Foo.new.bar= 7,8,9 ArgumentError: wrong number of arguments (1 for 3) from (irb):4:in `bar=' from (irb):4 from :0 >> The other way you can see it's sugar is that a space is allowed between x and =. -- Posted via http://www.ruby-forum.com/.