On Tue, 22 Aug 2006, Luke Kanies wrote:

> Hi all,
>
> I'm dynamically loading some ruby files, and those files need to call a 
> method on a module of mine.  E.g., in this case, the method is 
> Puppet::Parser::Functions.newfunction, and the files are autoloaded from 
> 'puppet/parser/functions/<funcname>.rb'.
>
> I'd like to load the files in a way that 'newfunction' could be called 
> without the full path to Puppet::Parser::Functions.; they call 'newfunction', 
> and it correctly resolves to the Functions module.
>
> Is there a way to load a file within an existing namespace, so that the 
> method search path started at the scope doing the loading?
>
> Thanks,
> Luke

food for thought:

   harp:~ > cat a.rb
   def context_load path, &context
     o = Object.new
     o.instance_eval &context
     o.instance_eval IO.read(path)
   end

   context_load 'b.rb' do
     def m() p 'foo' end
   end

   context_load 'b.rb' do
     def m() p 'bar' end
   end
   harp:~ > cat b.rb
   m()


   harp:~ > ruby a.rb
   "foo"
   "bar"


related

   http://codeforpeople.com/lib/ruby/dynaload/

regards.

-a
-- 
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama