Rules for constant lookup

B

Brian Candler

Can somebody point me to an *accurate* list of the rules for constant
lookup?

I've just been caught out by the following.

==> works.rb <==
module Foo
class Bar; end
class Baz
def initialize
@bar = Bar.new
end
end
end

Foo::Baz.new

==> broken.rb <==
module Foo
class Bar; end
end

class Foo::Baz
def initialize
@bar = Bar.new
end
end

Foo::Baz.new

In both cases there is a module Foo, a class Foo::Bar and a class
Foo::Baz. The only difference between the two is that one uses "module
Foo; class Baz" and the second uses "class Foo::Baz"

I thought the two were identical if module Foo already exists, but
clearly I was mistaken.

Regards,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top