From: sabbyxtabby@... (Sabby and Tabby) Date: 2004-03-14T20:29:35+09:00 Subject: Re: Extended information about a method's caller "Robert Klemme" wrote: > "Bill Atkins" schrieb im Newsbeitrag > news:20040312040924.AB9DF3977@mprdmxin.myway.com... > > > > Is there any way to get a list of the arguments passed to a method's > caller? I am aware of Kernel.caller, but it seems like it just gives a > method name. > > If you know the argument names you might be able to hack something together > with set_trace_func. But why don't you just pass them on? :-) Or, if you hacked something together with set_trace_func, you might[1] be able to know the argument names. :) module Kernel set_trace_func proc {|*a| $bind = a[4] unless a[3] == :argument_values } def argument_values eval <<-'CODE', $bind caller(0)[0] =~ /`(.*)'/ or return $arity = method($1).arity $args = local_variables[0, $arity.abs] $args[-1] = '*' + $args[-1] if $arity < 0 eval "[#{$args * ','}]" CODE end end class Test def test(x, *y) i = 0 z = 0..9 p argument_values end end Test.new.test(4, 5, 6) [1] The ordering of local variables returned by local_variables may be accidental.