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
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
"rolo" <rohitlodha@hotwireindia.com> schrieb im Newsbeitrag
news:ACEPLIKLBKEMDDIELPKIGEPICGAA.rohitlodha@hotwireindia.com...
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:
module Mod; BAR = "hello"; end
=> "hello"
Mod::BAR
=> "hello"
class Foo; include Mod; FOO = "world"; end
=> "world"
Foo::FOO
=> "world"
Foo::BAR
=> "hello"
Mod::FOO
NameError: uninitialized constant Mod::FOO
from (irb):6
Foo.ancestors
=> [Foo, Mod, Object, Kernel]
Foo.constants
=> ["BAR", "FOO"]
Mod.constants
=> ["BAR"]
Regards
robert
From: Robert Klemme [mailto:bob.news@gmx.net]
Sent: Thursday, June 10, 2004 4:34 PM
To: ruby-talk ML
Subject: Re: Who own the constants?"rolo" <rohitlodha@hotwireindia.com> schrieb im Newsbeitrag
news:ACEPLIKLBKEMDDIELPKIGEPICGAA.rohitlodha@hotwireindia.com...
> 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.
> 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:
Thanks for this info.
Regards,
rolo
-----Original Message-----