When calling an attribute writer created using either attr_accessor or attr_writer via send nil is returned from the send call instead of the new value.
I've attached a test case that is failing on current head (51794) and 2.0.0-rc1. I've done a git bisect and it looks like commit 37228 (db1e99cd) is the first offending commit.
I've been able to reproduce on OS X 10.8 and Ubuntu 12.04.
I consider it a bug because the behavior only happens using send.
Actually, it is not a bug itself.
An assignment-like method call always returns its right value rather than the return value from the method.
The following code shows the difference:
class Foo
def foo=(x)
"foo"
end
end
x = Foo.new
p(x.foo = 42) #=> 42
p(x.send(:foo=, 42)) #=> "foo"
However, as MarcAndre said, a method defined by attr_accessor used to return its argument, at least in ruby 1.9.3p194.
There seems to be a regression. Nobu, could you investigate it?
This issue was solved with changeset r39121.
Chris, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
vm_insnhelper.c: attr_writer should return its argument [Bug #7773]
test/ruby/test_basicinstructions.rb: Test for above