On Fri, 3 Sep 2004 21:50:46 +0900, Benny <linux / marcrenearns.de>
wrote:
> I have 2 files: main.rb and include_me.rb. I want include_me.rb to
> contain only the method definitions (dont have to care about its
> module and class).
> 
> [[background information: the real problem is a bit more
> complicated. finally 'main.rb' will open lots of different
> 'include_me.rb's in a loop and even check if it has already opened
> them before open them twice, but running classname.run each time
> in the loop (i.e. file name of the include and classname are
> variables passed to main.rb in the loop)]]

> the following code works, but
> - will it always work no matter whats in 'include_me.rb'?
> - is there a better solution to get rid of the evil "eval"?
> 
> I know there is send(:define_method, "method_name") but I want
> 'include_me.rb' to appear like if it would be a valid ruby script on its
> own (without using any "special methods" only for the inclusion purpose).
> 
> to simply redefine the same class in each include file is not an option.

Look at Kernel#load; there's a wrap option. When Ruby requires or
loads a file, the code in it is executed -- and then because you can
wrap the loaded file in a module, you can then run it as well.

-austin
-- 
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca
: as of this email, I have [ 6 ] Gmail invitations