On Mon, Feb 18, 2013 at 4:10 PM, connor culleton <[email protected]> wrote:
> Hi Everyone,
>
> I am working with a test framework which has a module where a lot of
> functionally has been defined.
>
>
> module Stuff
>     # lots_of_stuff...
> end
>
>
>  When the test framework starts this module is loaded.
>
> I am creating a controller class, which will be loaded for certain cases
> and I need access to the methods defined in the module "stuff".  Rather
> Crudely I have done this
>
> class MyController
>     include Stuff
> end
>
> So in essence "load Stuff" will be called twice.

What do you mean by that?  I do not see any "load" in your code at
all.  Keyword "include" will not load any code.  It will just insert
the module in the inheritance chain (see MyController.ancestors) for
method lookup.

Did you measure any timing issus?

> Is there a cost to
> doing this or will my class just get passed a pointer to all those
> functions that are all ready in memory?
>
> Or are there any nicer ways to do what I wanted?

You typically load code only once - either through "load" or even
better "require".

I am under the impression that you might confuse terms here.  Loading
typically means what "load" and "require" do: the source file is read
by the Ruby interpreter, parsed and compiled into some internal
representation.  When you include a module in a class nothing like
that happens.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to