Forum: Ruby including modules - ordering question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2007-06-27 06:36
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.
807270f56f26ad90755eef71f2c228fe?d=identicon&s=25 Alex Gutteridge (Guest)
on 2007-06-27 07:39
(Received via mailing list)
On 27 Jun 2007, at 13:36, Aryk Grosz 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 Gutteridge

Bioinformatics Center
Kyoto University
B57c5af36f5c1f33243dd8b2dd9043b1?d=identicon&s=25 F. Senault (Guest)
on 2007-06-27 11:21
(Received via mailing list)
Le 27 juin à 06:36, Aryk Grosz 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
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2007-06-27 19:21
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 topic is locked and can not be replied to.