I have a class that has an attribute named "an_attribute". I would like to define the following
The problem is every time I call the function, the return value is always "new_value" instead of
"false." Is there anyway for me to make it return "false"? Of course, the above simplistic example
is only used to illustrate what I want to ask.
I don't think there's any way. The = methods are engineered so as to
provide assignment-like semantics, and assignments always return their
You can circumvent this if you use send:
"Explicit return value"
self.x = 20
=> "Explicit return value"
(Thanks to Rick DeNatale for reminding me of the send thing in a
recent ruby-talk thread about this
But using send with a = method kind of defeats the purpose.