Hi --

On Wed, 30 Oct 2002, Mirian Crzig Lennox wrote:

> This is a little hard to explain, and I'm not sure if Ruby can
> actually do this, but here goes.
>
> I want to write a class with a method, say "method_handler" which
> "traps" all calls to undefined methods and executes them somehow.  For
> example:
>
> 	  class Foo
> 	    def	method_handler(meth, *args)
> 	      # meth is the symbol representing the name of the method
> 	      ... code to determine what happens ...
> 	    end
>           end
>
> I suspect that it may be possible to do this with an event, but I'm
> a little hazy on how that would work.

Your method_handler method is not missing; it's method_missing :-)

  irb(main):007:0> class X
  irb(main):008:1> def method_missing(m,*args)
  irb(main):009:2> puts "Call to #{m} with args #{args.inspect}!"
  irb(main):010:2> end
  irb(main):011:1> end
  nil
  irb(main):012:0> X.new.blah(123,456)
  Call to blah with args [123, 456]!


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav