From: Robert Klemme Date: 2006-03-30T21:58:43+09:00 Subject: Re: accessing the currently running method Kev Jackson wrote: > Currently I have > > caller[0][/in: `.+(pg_\d{3})/,1] > which adequately returns the current method (given the current > convention of naming the methods something with the page number in them) > > I tried > class Object > def current_method > caller[0][/in: `.+(pg_\d{3})/,1] > end > end > > but calls to this inside a method_missing method produce nil - not sure > why, but obviously I need to study more ruby to understand why that > doesn't work. Including current_method (as defined above) in module > Kernel also doesn't do the trick, but having the caller[0][/in: > `.+(pg_\d{3})/,1] inside the method_missing method works. Maybe you're calling method_missing again? Could be that you a) either need to provide a parameter to current_method that determines how many levels to go up or b) you cannot do what you want because once method_missing is invoked your original method name is lost: >> o=Object.new => # >> def o.method_missing(s,*a,&b) p caller; p s; end => nil >> def o.bar() foo() end => nil >> o.bar ["(irb):7:in `bar'", "(irb):8:in `irb_binding'", "/usr/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'", ":0"] :foo => nil "foo" doesn't show up in caller, but method_missing has the symbol (first arg). > Thanks for pointing me in the direction of a couple of new things You're welcome! Kind regards robert