I have a base module that has desirable class defined on it like so:
module Base
class Desirable
end
end
Now inside a nested module chain (in Base::Nested1
) I would like to derive from this class. I first tried to do this like so:
module Base::Nested1
class Derived < Desirable
end
end
this throws an error:
uninitialized constant Base::Nested1::Desirable
If I declare it like this however:
module Base
module Nested1
class Derived < Desirable
end
end
end
I get no errors.
The errors are caused by this section of the const_missing
method (in rails activesupport 5.0.1):
517 elsif (parent = from_mod.parent) && parent != from_mod &&
518 ! from_mod.parents.any? { |p| p.const_defined?(const_name, false) }
519 # If our parents do not have a constant named +const_name+ then we are free
520 # to attempt to load upwards. If they do have such a constant, then this
521 # const_missing must be due to from_mod::const_name, which should not
522 # return constants from from_mod's parents.
My problem is I don't understand the comment of that code; why should we not be loading this constant from the parent module in this case?