Project

General

Profile

Actions

Bug #1698

closed

Incorrect return value for writer methods.

Added by falter (Mike Ryan) almost 15 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
ruby -v:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9]
[ruby-core:24073]

Description

=begin
I found the following behavior this past week and found it a bit odd.

irb(main):001:0> class Foo
irb(main):002:1> def bar=(bla)
irb(main):003:2> @bar = bla * 2
irb(main):004:2> end
irb(main):005:1> def bar
irb(main):006:2> @bar
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> a = Foo.new
=> #Foo:0x13f880
irb(main):010:0> a.bar = 10
=> 10
irb(main):011:0> a.bar
=> 20
irb(main):012:0> a.send(:bar=, 7)
=> 14
irb(main):013:0> a.bar
=> 14
irb(main):014:0> a.bar=(3)
=> 3
irb(main):015:0> a.bar
=> 6

You'll see that line 10 returns the value that we are passing to the bar=(bla) method, but not the actual return value.

Not certain if it was because I wasn't explicitly returning a value, I found that this did not matter:

irb(main):001:0> class Foo
irb(main):002:1> def strange=(bla)
irb(main):003:2> return "correct return value"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> a = Foo.new
=> #Foo:0x86df8
irb(main):007:0> a.strange = "this is strange"
=> "this is strange"
irb(main):008:0> a.send(:strange=, "this is also strange")
=> "correct return value"

I see this in both 1.9.1p129 and 1.8.7p72.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0