Project

General

Profile

Bug #6097

Weird constant behavior during inheritance...

Added by Denis de Bernardy almost 4 years ago. Updated almost 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
ruby -v:
1.9.3
Backport:
2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
[ruby-core:42979]

Description

class Parent
class Child
def foo
end
end
end
=> nil
class Test < Parent
end
=> nil
Test.const_defined?(:Child)
=> true
class Test
class Child
def bar
end
end
end
=> nil
Test::Child.new.respond_to?(:bar)
=> true
Parent::Child.new.respond_to?(:bar)
=> false # true expected...

Obviously, testing the object_id shows that Parent::Child and Test::Child are not the same class, but is this to be expected?

History

#1 [ruby-core:42980] Updated by Xavier Noria almost 4 years ago

Once Test::Child gets defined, both Parent and Test have Child among their very constants (and they are different classes). The ancestry chain is not even checked.

#2 [ruby-core:42986] Updated by Yukihiro Matsumoto almost 4 years ago

  • Status changed from Open to Rejected

Learn Ruby-way, please.

Also available in: Atom PDF