Bug #7773
closed
Calling send("attribute=", value) returns nil instead of value
Added by gaffneyc (Chris Gaffney) almost 12 years ago.
Updated almost 12 years ago.
Description
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.
Files
- Status changed from Open to Feedback
Why do you consider it a bug?
- Category set to core
- Status changed from Feedback to Open
- Target version set to 2.0.0
nobu (Nobuyoshi Nakada) wrote:
Why do you consider it a bug?
I don't know about Chris, but here is why I consider it a bug:
- returning nil is less useful than value
- it is less intuitive too (to me)
- it is a change of behavior (possibly breaking some existing code)
- this change of behavior was never announced, discussed or approved AFAIK
- the referred commit has no stated or implied intention to change this
- the referred commit has no test to that effect
What I wonder is: why do you consider it could possibly be a feature?
I consider it a bug because the behavior only happens using send
. If I were to call bar=
directly (see below) it returns the value that was set.
class Foo
attr_writer :bar
end
Foo.new.bar = "test" # => "test"
Should send
behave differently than sending the message directly?
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
gaffneyc (Chris Gaffney) wrote:
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?
--
Yusuke Endoh mame@tsg.ne.jp
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
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.
I meant to assign it to myself... in any case, it's fixed with r39121.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0