Why in below code snippet foo replaces its definition?
def foo
def foo
1
end
end
for the first time foo is nil
foo
=> nil
foo.foo
=> 1
Now if I call foo again:
foo
=> 1
As you can see foo is not nil anymore. Can some one explain this to me? thanks.
Also, when you call
foo.foo, it seems like you’re trying to access the innerfoomethod, but it doesn’t work that way. Yourfoomethod is actually defined onObject, so you’re actually calling1.foo.