In the following test case:
class Package
class Component
def initialize
p [:initialize,self]
end
end
end
class Package_A < Package
end
class Package_B < Package
end
# Why are the following components of type Package and not Package_A and Package_B
component=Package_A::Component.new
p component
component=Package_B::Component.new
p component
Results in:
[:initialize, #<Package::Component_1:0x2c0a8f8>]
#<Package::Component:0x2c0a8f8>
[:initialize, #<Package::Component_1:0x2c0a5b0>]
#<Package::Component:0x2c0a
How do I get a specific Package_A.component and Package_B.component?
Class
Componentis declared inPackage, so it seems correct. The::tells to look up the nameComponentin the scope ofPackage_A. Since there is noComponentthere, it looks up the superclass.This example shows how to achieve what you want. There might be a simpler way, I would be happy to see it.
This more-less should explain how scope works in such cases. Hope this helps.