The thing is that this actually isn't ambiguous — it's just not intuitive. In Ruby's grammar, an identifier that starts with a capital letter and isn't followed by an argument list is always parsed as a constant lookup.
You would get the same error even if you had defined a method like def Foo "You won't see this" end
. When it encountered Foo
, it would still try to look up the constant Foo
and throw a NameError when no constant by that name was found. In order to call a method that starts with a capital letter, you have to include an explicit receiver (e.g. self.Foo
) or an argument list (if only an empty one).