From: Sam Roberts Date: 2004-02-13T05:07:22+09:00 Subject: Re: Return value of foo= Quoteing gavin@refinery.com, on Fri, Feb 13, 2004 at 04:59:58AM +0900: > The question is, is it possible to change the return value of a foo= > method to NOT be the argument? Sure, lots of builtin classes do it, for example. It works as you expect: [ensemble] ~/p/ruby $ irb irb(main):001:0> class Foo; def bar=(b); @bar = b; self; end; def bar; @bar; end; end nil irb(main):002:0> f = Foo.new # irb(main):003:0> f.bar = 9 # irb(main):004:0> f.bar 9 So, I guess the question is why it don't work for you... and I have no idea. :-) Sam > If the answer is no, well, I can sort of see why (consistency of > expectations for something like: bar = obj.foo+=3) but I also feel > like...if it's a method, it's a method, whatever syntax is invoking it. > Shouldn't I be able to control the return value? > > Please see the code below. > > ######################## > > class MutableTime > ... > def date > @t.day > end > def date=(n) > @t+=(n-date)*DINS > self # < == LOOK HERE! > end > ... > end > > ######################## > > puts t3 = MutableTime.new("2/8/2004 2:37:13pm") > => Sun Feb 08 14:37:13 MST 2004 > > puts t3.date > =>8 > > puts t3.date=11 > => 11 # <== GRR! I want the object instance to be the return value > > puts t3.date > => 11 > > puts t3 > => Wed Feb 11 14:37:13 MST 2004 >