https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-02-06T21:59:54ZRuby Issue Tracking SystemRuby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=358962013-02-06T21:59:54Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Why do you consider it a bug?</p> Ruby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=359232013-02-07T00:06:03Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Open</i></li><li><strong>Target version</strong> set to <i>2.0.0</i></li></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>Why do you consider it a bug?</p>
</blockquote>
<p>I don't know about Chris, but here is why I consider it a bug:</p>
<ul>
<li>returning nil is less useful than value</li>
<li>it is less intuitive too (to me)</li>
<li>it is a change of behavior (possibly breaking some existing code)</li>
<li>this change of behavior was never announced, discussed or approved AFAIK</li>
<li>the referred commit has no stated or implied intention to change this</li>
<li>the referred commit has no test to that effect</li>
</ul>
<p>What I wonder is: why do you consider it could possibly be a feature?</p> Ruby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=359262013-02-07T01:01:19Zgaffneyc (Chris Gaffney)gaffneyc@gmail.com
<ul></ul><p>I consider it a bug because the behavior only happens using <code>send</code>. If I were to call <code>bar=</code> directly (see below) it returns the value that was set.</p>
<p>class Foo<br>
attr_writer :bar<br>
end</p>
<p>Foo.new.bar = "test" # => "test"</p>
<p>Should <code>send</code> behave differently than sending the message directly?</p> Ruby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=359272013-02-07T01:13:47Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul><p>gaffneyc (Chris Gaffney) wrote:</p>
<blockquote>
<p>I consider it a bug because the behavior only happens using <code>send</code>.</p>
</blockquote>
<p>Actually, it is not a bug itself.<br>
An assignment-like method call always returns its right value rather than the return value from the method.<br>
The following code shows the difference:</p>
<p>class Foo<br>
def foo=(x)<br>
"foo"<br>
end<br>
end<br>
x = Foo.new<br>
p(x.foo = 42) #=> 42<br>
p(x.send(:foo=, 42)) #=> "foo"</p>
<p>However, as MarcAndre said, a method defined by attr_accessor used to return its argument, at least in ruby 1.9.3p194.<br>
There seems to be a regression. Nobu, could you investigate it?</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=359362013-02-07T02:31:26Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r39121.<br>
Chris, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>vm_insnhelper.c: attr_writer should return its argument [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Calling send("attribute=", value) returns nil instead of value (Closed)" href="https://redmine.ruby-lang.org/issues/7773">#7773</a>]</p>
</li>
<li>
<p>test/ruby/test_basicinstructions.rb: Test for above</p>
</li>
</ul> Ruby master - Bug #7773: Calling send("attribute=", value) returns nil instead of valuehttps://redmine.ruby-lang.org/issues/7773?journal_id=359372013-02-07T02:33:33Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>I meant to assign it to myself... in any case, it's fixed with r39121.</p>