# Rules for constant lookup

**URL:** <https://www.ruby-forum.com/t/rules-for-constant-lookup/182170>\
**Category:** Ruby\
**Created:** [January 23, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/rules-for-constant-lookup/182170 "2010-01-23T21:46:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [January 23, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/rules-for-constant-lookup/182170/1 "2010-01-23T21:46:09Z")

</div>

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.
