Including modules - ordering question

Hi,

I have a module where I include modules as usual:

module A
module B
end
module C
include B
include D
end
module D
end

end

When I require this file, I’ll get an error here because module D is
being included before it gets loaded. I would need to put it above
module C to get it to work. How can I load the file, and then do all the
includes so that it can actually find the module.

On 27 Jun 2007, at 13:36, Aryk G. wrote:

end
module D
end

end

When I require this file, I’ll get an error here because module D is
being included before it gets loaded. I would need to put it above
module C to get it to work. How can I load the file, and then do
all the
includes so that it can actually find the module.

Perhaps I’m missing something, but haven’t you answered your own
question…

I would need to put it above module C to get it to work.

So the structure of the file should look like this:

module A
module B
end
module D
end
module C
include B
include D
end
end

Perhaps there is something more complicated going on in your example
that I am not understanding?

Alex G.

Bioinformatics Center
Kyoto University

Le 27 juin à 06:36, Aryk G. a écrit :

When I require this file, I’ll get an error here because module D is
being included before it gets loaded. I would need to put it above
module C to get it to work. How can I load the file, and then do all the
includes so that it can actually find the module.

Not sure how (if) it would work, but can’t you just define an empty
Module D with “module D ; end” and then reopen it after :

module A
module B
# code
end
module D ; end
module C
include B
include D
# code
end
module D
# code
end
end

Fred

Well, basically Im looking for a solution where order doesn’t matter.
Hmm, I wonder if that trick with the module would work. It’s kind of
hacky. Wonder if there is a better way or maybe you just have to be
aware of order all the time.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs