I have a module B which gets mixed in to a module I, like this:
module B
BC = 4711
def g
puts ‘works’
end
end
module I
extend self
extend B
def f
g
puts B::BC
end
end
If I invoke
I.f
I get the output
works
4711
as expected. From I::f, I can invoke g directly, as if it had been
defined inside I, because I included B using extend B. For accessing the
constant BC, I have to qualify it explicitly, B::BC.
Is there a way I can access the constants in B from within I without
qualification with the module name?
I never had considered doing include AND extend together.
The complexity of the solution makes me wonder, whether what I want to
achieve is really still in “Ruby spirit”. Maybe my thinking was
influenced too much by other languages (C++ namespaces for instance). Am
I the (nearly) only one who wants to use modules in this way?
In any case: Thanks a lot! Your suggestions helps indeed.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.