I tried to capture undefined methods by the following definition:
def method_missing m
puts "#{m} is missing"
end
When I write an undefined method such as foo
after it, it is captured by method_missing
:
foo # => foo is missing
but when I write an undefined method such as Foo
, it is not captured by method_missing
:
Foo # => NameError: Uninitialized constant Foo
It looks like if it is disambiguated from a constant, then it is captured:
self.Foo # => Foo is missing
Foo() # => Foo is missing
Why is Foo
not captured in the first case? Is it a feature that when a method is ambiguous between a local variable, it is captured by method_missing
, but not when it is ambiguous between a constant? If so, is there documentation on this? Or, is it a bug?