From: Ezra Zygmuntowicz Date: 2008-02-25T09:29:31+09:00 Subject: Re: Suprising behaviour with "def property=" method On Feb 24, 2008, at 2:41 PM, Farrel Lifson wrote: > I had a bit of a surprise with the following > > class Foo > def bar(value) > @bar = value.upcase > end > end > > f = Foo.new > my_bar = (f.bar = "bar") > > I initially thought that my_bar would == "BAR" but in fact it equals > "bar". It seems no matter what the final value of the bar= method is > the return value is always the parameters. First time I've run into > this so I thought I would share and ask if anyone can think of anyway > to get around this? > > Farrel This is just the way ruby works. It *always* returns the right hand side of any method call ending in =. This is for consistency sake. since you can write methods that look like assignment it keeps things consistent to always return the rhs of any assignment. Cheers- - Ezra Zygmuntowicz -- Founder & Software Architect -- ezra@engineyard.com -- EngineYard.com