How does the following code work, and more importantly, why does it work this way?
class Example
def one
def one
@value = 99
end
puts "Expensive Call"
@value = 99
end
end
ex = Example.new
puts ex.one
puts ex.one
Here, when the method is first called, oneRuby executes the external onemethod, but in subsequent calls, it only executes the internal method one, completely bypassing the external method one.
I want to know how this happens and why it happens.
source
share