# Where's A?

**URL:** <https://www.ruby-forum.com/t/wheres-a/120771>\
**Category:** Ruby\
**Created:** [November 20, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/wheres-a/120771 "2007-11-20T14:54:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 20, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/wheres-a/120771/1 "2007-11-20T14:54:32Z")

</div>

This doesn’t seem right to me:

irb(main):001:0\> module X  
irb(main):002:1\> module A; end  
irb(main):003:1\> end  
=\> nil  
irb(main):004:0\> class Q  
irb(main):005:1\> include X  
irb(main):006:1\> p A  
irb(main):007:1\> class Y  
irb(main):008:2\> class Z \< A  
irb(main):009:3\> end  
irb(main):010:2\> end  
irb(main):011:1\> end  
X::A  
NameError: uninitialized constant Q::Y::A  
from (irb):8

If I recall correctly, 1.9 has some changes to constant lookup rules.  
Is the above fixed in 1.9?

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 20, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/wheres-a/120771/2 "2007-11-20T23:17:41Z")

</div>

On Nov 20, 2007 1:53 PM, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):008:2\> class Z \< A  
> Thanks,  
> T.

Hi Trans,

I’m not sure I understand what you expect. In the following example:

class A  
end

module Outer  
module X  
class A # you meant ‘class’ didn’t you? 😉  
end  
end

class A  
end

class Q  
include X  
class Y  
p A  
class Z \< A # which A do you want?  
end  
# this seems reasonable to me…  
class XZ \< X::A  
end  
end  
end  
end

which A should Z be a subclass of?

Regards,  
Sean

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [November 21, 2007, 3:34am UTC](https://www.ruby-forum.com/t/wheres-a/120771/3 "2007-11-21T03:34:55Z")

</div>

On Nov 20, 5:17 pm, “Sean O’Halpin” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > irb(main):006:1\> p A  
> > Is the above fixed in 1.9?
> 
> module Outer  
> module X  
> class A # you meant ‘class’ didn’t you? 😉

Oops. Yes.

> ```
> class Z < A # which A do you want?
> end
> # this seems reasonable to me...
> class XZ < X::A
> end
> end
> 
> ```
> 
> end  
> end
> 
> which A should Z be a subclass of?

Fair question. I would expect the closest, and in this case it would  
be the one defined in X, since that’s what is asked for in the  
namespace with “include X”. The problem with the way it is now is very  
much like the problem with XML namespaces. That X::, which seems so  
reasonable here turns into Some::Deep::Space:: in real life. And if  
we’re defining a number of such subclasses (as I am) we have to repeat  
it over and over. No fun.

However, I did find a trick.

module X  
class A  
include X  
end  
end

This helps once I get past the first subclass (all subsequent  
subclasses can see all of X). Weird, huh?

T.
