Sure. This makes sense. But why the difference in visibility of the
constant Trouble?
It’s not exactly visibility – const_defined? tells you whether that
constant was/is defined in that module, not just whether the module
can see it. For example:
irb(main):001:0> class A; X = 1; end
=> 1
irb(main):002:0> class B < A; end
=> nil
irb(main):003:0> B::X
=> 1
irb(main):004:0> A.const_defined?(“X”)
=> true
irb(main):005:0> B.const_defined?(“X”)
=> false
irb(main):006:0> class B; X = 2; end
=> 2
irb(main):007:0> B.const_defined?(“X”)
=> true
David
···
On Wed, 21 May 2003, Dan Janowski wrote:
On Wednesday, May 21, 2003, at 10:25 America/New_York, ts wrote:
Sure. This makes sense. But why the difference in visibility of the
constant Trouble?
I don't understand, you want to say the difference between
Module::const_defined? and Module::constants
svg% ri const_defined?
-------------------------------------------------- Module#const_defined?
mod.const_defined?( aSymbol ) -> true or false
···
------------------------------------------------------------------------
Returns true if a constant with the given name is defined by mod.
Math.const_defined? "PI" #=> true
svg%
svg% ri Module::constants
------------------------------------------------------ Module::constants
Module.constants -> anArray
------------------------------------------------------------------------
Returns an array of the names of all constants defined in the
system. This list includes the names of all modules and classes.
p Module.constants.sort[1..5]
produces:
["ARGV", "ArgumentError", "Array", "Bignum", "Binding"]