class Test
attr_accessor :something
end
class Test
alias :old_something= :something=
def something=(a)
a += 2 # do something with the argument
old_something=(a) # then pass it on
end
end
我希望如果我说
t = Test.new
t.something = 3
puts t.something
它会打印出来5
。但它打印nil
。为什么这不起作用?