From: Simon Strandgaard Date: 2003-11-17T10:23:06+09:00 Subject: Re: overload method in module_eval, how? On Mon, 10 Nov 2003 16:43:20 +0100, ts wrote: >>>>>> "S" == Simon Strandgaard writes: > > S> Still only the first output statement are working. > S> I don't understand why the successive print-statements doesn't output > S> anything. Any hints ? > > > I've given the hint : method is a Symbol, and the method Symbol#arity is > not defined. > > You must first call Kernel#method with the symbol as argument and then > call arity > > svg% ruby -e 'def test_x() end; method = :test_x; p method(method).class' > Method > svg% > > svg% ruby -e 'def test_x() end; method = :test_x; p method(method).arity' > 0 > svg% I think I do symbol2method lookup wrong. How does I lookup the symbol in the instance namespace ? -- Simon Strandgaard server> ruby test_dbg.rb ["test_x"] symbol = test_x ERROR: symbol2method failure, # method = method.class = NilClass Loaded suite test_dbg Started .. Finished in 0.002409 seconds. 1 tests, 1 assertions, 0 failures, 0 errors server> expand -t2 test_dbg.rb require 'test/unit' class Object def self.debug(*args) p instance_methods(false) args.each{|symbol| puts "symbol = #{symbol}" begin meth = method(symbol) rescue => e puts "ERROR: symbol2method failure, " + e.inspect end puts "method = #{meth}" puts "method.class = #{meth.class}" n = meth.arity puts "arity=#{n}" name = symbol.id2name org = "_debug_"+name arguments = (n != 0) ? "(*a,&b)" : "(&b)" code=<