From: Tony Arcieri Date: 2010-03-12T08:57:50+09:00 Subject: Re: result of assignment is not the return value --0016e68fd04f7c808b04818f2ef6 Content-Type: text/plain; charset=ISO-8859-1 Setters always return the value they were originally assigned On Thu, Mar 11, 2010 at 4:55 PM, Nathan Beyer wrote: > Given a simple class like this > > class MyClass > attr_reader :value > def value=(val) > @value = val.to_s > end > end > > Why the the following code return the value passed and not the value > assigned? > > c = MyClass.new > result = c.value = 2 > puts result > puts c.value > > This is currently outputing > > 2 > "2" > > The results are the same when MyClass is modified to be this. > > class MyClass > attr_reader :value > def value=(val) > @value = val.to_s > return @value > end > end > > Shouldn't the result of the 'value=' method be the return value? > > -- Tony Arcieri Medioh! A Kudelski Brand --0016e68fd04f7c808b04818f2ef6--