Are you an advanced rubyist?
Try to do this by memory without using a ruby interpreter.
Given:
class Test
def attr
@attr
end
def attr=(value)
@attr = value * 2
end
end
Evaluate: t = Test.new
t.attr = 5 # Returns => ?
t.attr # Returns => ?
I don't consider myself an advanced rubyist, and I couldn't answer this until today. Nonetheless, the behavior surprised me. I've read a number of books about ruby and never seen this behavior mentioned; in fact, most deem a setter method as just another method. Any explanation for this behavior?