K
Kevin Howe
It seems that const_defined? doesnt search it's superclass:
class A
FOO = 'BAR'
end
class B < A; end
puts A.const_getFOO) # => 'BAR'
puts A.const_defined?FOO) # => true
puts B.const_getFOO) # => 'BAR'
puts B.const_defined?FOO) # => false
I had expected B.const_defined?FOO) to be true. Seems strange that
const_get does the lookup while const_defined? doesn't. Is there a reason
for this behaviour?
The following takes care of it:
class A
def self.const_defined?(symbol) super ||
superclass.const_defined?(symbol) end
end
But would like to know why this is.
Regards,
Kevin
class A
FOO = 'BAR'
end
class B < A; end
puts A.const_getFOO) # => 'BAR'
puts A.const_defined?FOO) # => true
puts B.const_getFOO) # => 'BAR'
puts B.const_defined?FOO) # => false
I had expected B.const_defined?FOO) to be true. Seems strange that
const_get does the lookup while const_defined? doesn't. Is there a reason
for this behaviour?
The following takes care of it:
class A
def self.const_defined?(symbol) super ||
superclass.const_defined?(symbol) end
end
But would like to know why this is.
Regards,
Kevin