Const_missing oddity?


#1

def Object.const_missing name
puts “There is no constant: #{name}”
end

irb(main):038:0> Foo { puts “here!”}
NoMethodError: undefined method `Foo’ for main:Object
from (irb):38
from :0

irb(main):039:0> Foo
There is no constant: Foo
=> nil

So the block after Foo keeps Foo from being recognized as a constant?
(apparently it’s recognized as a method instead)

Phil


#2

Hi –

On Thu, 2 Mar 2006, Phil T. wrote:

irb(main):039:0> Foo
There is no constant: Foo
=> nil

So the block after Foo keeps Foo from being recognized as a constant?
(apparently it’s recognized as a method instead)

That’s what I would expect – otherwise you’d have a situation where
methods with capitalized names couldn’t take blocks. The same is true
of Foo() with respect to arguments.

David


David A. Black (removed_email_address@domain.invalid)
Ruby Power and Light (http://www.rubypowerandlight.com)

“Ruby for Rails” chapters now available
from Manning Early Access Program! http://www.manning.com/books/black