Why foo is not nil anymore - or function within function
ruby
Solution
def foo
p "about to redef foo"
def foo
1
end
end
foo
"about to redef foo"
=> nil
foo
=> 1
Also, when you call `foo.foo`, it seems like you’re trying to access the inner `foo` method, but it doesn’t work that way. Your `foo` method is actually defined on `Object`, so you’re actually calling `1.foo`.
Problem
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.