On 13 Dec 2006, at 14:47, ao tianlong wrote:

>  1 class Book
>  2 def method_missing(method_id,*params,&block)
>  3 print 'original method missing'
>  4 end
>  5
>  6 alias :original_method_missing :method_missing
>  7 def method_missing(method_id,*params,&block)
>  8 C(params[:comment])print 'my method missing'
>  9 original_method_missing(method_id,*prams,&block)
> 10 end
> 11 end
> 12
> 13 book = Book.new
> 14 book.tester
>
> its looks like work , but output is
> thod missingmy method missingmy method missingmy method missingmy  
> method
> missingmy method missingmy method missingmy method missingmy method
> missingmy method missingmy method missingmy method missingmy method
> missingmy method missingmy method missingmy method missingmy method
> missingmy method missintest.rb:9:in `method_missing': stack level  
> too deep
> (SystemStackError)
>        from test.rb:9:in `method_missing'
>        from test.rb:14
>
> any idia?
>

You are calling a missing method from within your new method_missing.  
Infinite recursion ensues.

The following seems to work:

irb(main):001:0> class Book
irb(main):002:1> def method_missing(mtd,*arg,&blk)
irb(main):003:2> puts "Original"
irb(main):004:2> end
irb(main):005:1> alias :original :method_missing
irb(main):006:1> def method_missing(mtd,*arg,&blk)
irb(main):007:2> puts "New"
irb(main):008:2> original(mtd,*arg,&blk)
irb(main):009:2> end
irb(main):010:1> end
=> nil
irb(main):011:0> Book.new.test
New
Original
=> nil

Alex Gutteridge

Bioinformatics Center
Kyoto University