Daniel Sheppard
12/7/2006 12:14:00 AM
> In my opinion, if I understood the problem correctly, if a
> function/method ends with a 'return self (or whatever)' then
> that's what
> should be returned. There is no acceptable excuse for nor
> returning it.
Which is exactly what the method will do... if you call it as a method.
When you call it as an assignment, it returns the assigned value.
Anything else would give rise to confusion of anybody trying to
understand the code when used.
class A
def a=(x)
@x = x
return "blah"
end
end
A.new.a='xx'
=> 'xx'
A.new.send(:a=,'xx')
=> 'blah'
It also stops you from shooting yourself in the foot with:
class A
def a=(x)
@x = x
recalculate_things
end
end
Which would return the result of recalculate_things... an unexpected
result,
and I'm guessing the motivation behind the change.
Dan.