Ooh, ooh, I can do this one!!11!11
'some_file.rb'
module Foo
class Baz
def woot; 'hello I am in Foo'; end
end
end
'some_other_file.rb'
module Bar
class Baz
def woot; 'hello I am in Bar'; end
end
class Pork
def woot
b = Baz.new # refers to Bar::Baz
b2 = Foo::Baz.new # refers to the other Baz
end
end
end
'my_file.rb'
require 'some_file'
require 'some_other_file'
fb = Foo::Baz.new
bb = Bar::Baz.new
···
-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Wes Gamble
Sent: Tuesday, May 16, 2006 3:19 PM
To: ruby-talk@ruby-lang.org
Subject: Need help understanding namespace rules-modules and classes
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
module?
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.
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
This e-mail message may contain privileged and/or confidential information,
and is intended to be received only by persons entitled to receive such
information. If you have received this e-mail in error, please notify the
sender immediately. Please delete it and all attachments from any servers,
hard drives or any other media. Other use of this e-mail by you is strictly
prohibited.
All e-mails and attachments sent and received are subject to monitoring,
reading and archival by Seminis. The recipient of this e-mail is solely
responsible for checking for the presence of "Viruses" or other "Malware".
Seminis accepts no liability for any damage caused by any such code
transmitted by or accompanying this e-mail or any attachment.