This is called the “Dyanmic Module Inclusion Problem”. And Pit is
right, it is an implmentation issue. I think Matz would love to have a
fix for it, but appearently it is difficult, if not impossible, to do
so efficiently,
Thanks both of you for your insight. I’ve created a small hack to fix
that issue
class Module
Weird hack to ensure deep inclusion of modules
def include_deep(mod)
include mod
ancestors[1…-1].select do |a|
a != mod and not a.ancestors.include?(mod)
end.each { |a| a.include_deep(mod) }
end
end
Hmm… Doesn’t seem to do anything. Notice even without the above one
can instantiate a class and the mothod will “magically” showup. From
your example:
Hmm right, let me correct that
doh’ I would need to find the children and not the ancestors [C] of
the module (B) in which in include the other (A)… I guess it’s
doable by browsing the ObjectSpace but it’s quite expensive. If only
modules and classes would also list their childrens. Which is also
doable by overriding Module#included I guess but it’s not really
reliable isn’t it ?
end
Hmm… Doesn’t seem to do anything. Notice even without the above one
can instantiate a class and the mothod will “magically” showup. From
your example:
class X
include B
end
X.new.somemethod
T.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.