From: ao tianlong Date: 2006-12-13T16:53:49+09:00 Subject: Re: how to add a method_missing method into ActiveRecord ------=_Part_699_10743889.1165996425743 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline thank you i find the error original_method_missing(method_id,*prams,&block) it's misspelled *params as prams thank you again. On 12/13/06, Alex Gutteridge wrote: > > 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 > > > > ------=_Part_699_10743889.1165996425743--