On 24 Jul 2005, at 10:15, Stephan K?mper wrote:

> Hi all,
>
> I just ran into this situation: There's a module which uses DL to  
> provide calls into a dynamic library. Now, I'd like to make these  
> functions of the dyn. lib. available via DRb. (If I remember  
> correctly, I somewhere read that "include ModuleThatUsesDL" is not  
> a good idea to do, if that module uses DL in turn.)
>
> With the code below, I get this error message:
>
> -------------------------------------------------
> (druby://localhost:42000) c:/ruby/lib/ruby/1.8/drb/drb.rb:1419:in  
> `check_insecure_method': undefined method `a_method' called for  
> #<TheProxy:0x2911e98> (NameError)
>     from (druby://localhost:42000) c:/ruby/lib/ruby/1.8/drb/drb.rb: 
> 1461:in `check_insecure_method'
>
> So the question is: How can I get this to work?
> I would be grateful for information about this.
>
> And here's the boiled down code:
>
> # The Module (uses DL in real life)
> # Filename: 'the_module.rb'
> module TheModule
>   def a_method
>     "result"
>   end
> end
> -------------------------------------------------
>
> # The Proxy (provide access to the Module methods)
> # Filename: 'the_proxy.rb'
> require 'drb'
> require 'English'
> require 'the_module'
>
> class TheProxy
>
>   # I seem to recall that doing this is bad in case
>   # the module uses DL (but where did I read that?)
>   # include TheModule
>
>   def method_missing( meth_name, *arguments )
>     call_it = "#{ meth_name.to_s }( #{arguments.join( ', ' )} )"
>     if TheModule.respond_to? meth_name
>       TheModule.instance_eval( call_it )
>     else
>       raise NoMethodError, "Can't handle method '#{ call_it }'",  
> caller

You can super here.

>     end
>   end

You also need to have a respond_to? method that returns true for  
proxied methods.

> end

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04