From: Rick DeNatale Date: 2009-07-12T23:08:05+09:00 Subject: Re: A clean way to edit a time? On Sun, Jul 12, 2009 at 9:14 AM, David A. Black wrote: > To start with the last point: the setter methods are engineered to > look like and behave like assignments. So when you do this: > >  obj.x = y > > it always returns y. It's emulating assignment semantics: > >  x = y   # always returns y > > So using 'return' with an argument in those methods doesn't work. I think to be brutally correct, it's not that a return in a setter method doesn't work it's that obj.x = y will call the setter method with y as the argument, and discard any return value. The value of the assignment expression will always be the value of y, not the value returned by the setter method. whereas obj.send("x=", y) will evaluate to the return value of the setter. class Foo attr_reader :x_squared def x=(value) @x_squared = value * value end end obj = Foo.new obj.x = 4 # => 4 obj.x_squared # => 16 obj.send("x=", 3) # => 9 obj.x_squared # => 9 -- 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