Who own the constants?

R

rolo

Hi

Who keeps the constants defined within a Module of the Class?

The Class in which it is defined or the last module in the class hierarchy ?

Regards,
Rohit
 
R

Robert Klemme

rolo said:
Hi

Who keeps the constants defined within a Module of the Class?

What do you mean by "Module of the Class"?
The Class in which it is defined or the last module in the class hierarchy
?

Constants are always owned by the module or class they are defined in
although they are accessible from modules / classes that inherit the
defining class:
NameError: uninitialized constant Mod::FOO
from (irb):6
Foo.ancestors => [Foo, Mod, Object, Kernel]
Foo.constants => ["BAR", "FOO"]
Mod.constants
=> ["BAR"]

Regards

robert
 
R

rolo

-----Original Message-----
From: Robert Klemme [mailto:[email protected]]
Sent: Thursday, June 10, 2004 4:34 PM
To: ruby-talk ML
Subject: Re: Who own the constants?



rolo said:
Hi

Who keeps the constants defined within a Module of the Class?

What do you mean by "Module of the Class"?

Sorry. Typo. Module or the Class.
class hierarchy
?

Constants are always owned by the module or class they are defined in
although they are accessible from modules / classes that inherit the
defining class:

Thanks for this info.

Regards,

rolo
 

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
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top