Forum: Ruby Need help understanding namespace rules-modules and classes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-05-17 02:18
I'm having a namespace collision and I think I need some basic
understanding of how Ruby is managing namespaces.  I am 99% sure I know
which namespaces are colliding, but I'm not completely clear on how to
resolve it.

I have Module A (rubyful_soup.rb) which defines class Tag.  It appears
that this Tag class is not defined inside of a module.

I have Module B (node.rb) which defines class Tag.  It appears that this
Tag class is defined inside of a module called HTML.

However, I seem to be unable to avoid a "wrong number of arguments"
error when an attempt is made to instantiate Tag in node.rb, and I am
pretty sure that Tag from rubyful_soup.rb is interfering.

Here are my questions:

1) If I define a class _inside_ of a module, and then address that class
by module_name::class_name, should that ensure that I will get that
class?  Is the namespace actually defined by the module names or not?

2) Assuming that module::class is the correct way to address the class,
then _within_ a module, would I need to address my classes using
module::class consistently or can I just use the class name in the

Can someone give me an example of how I could address having two
different classes of the same name in two different modules?

I'm just not understanding what the equivalent of the Java package
structure is in Ruby.

This topic is locked and can not be replied to.