From: Paul McMahon Date: 2008-12-04T19:01:10+09:00 Subject: [ruby-core:20304] Re: Proposal: Method#get_args I am late to this discussion, but I am a bit concerned about the handling of default arguments, as you seem to be returning the result of the calculated default arguments every time you call get_args. For example: def foo(bar=[]); end method(:foo).get_args #=> [[[:bar, []]], nil, nil] I am assuming everytime get_args gets called, a new array is created. Now if the default argument is something like an array or string, this isn't a problem. However, the value for a default argument can be an ruby statement, whose result is calculated each time the method is invoked. For instance, a contrived example is: $i = 0 def foo(bar=($i +=1)); end foo $i #=> 1 Now, the way your get_args is working, if you call get args; method(:foo).get_args #=> [[[:bar, 2], nil, nil] $i #=> 2 This is probably unexpected and undesirable behaviour. You could get around this by returning a Proc in the tuple, but perhaps something more object oriented would be nicer in the first place. For example, m = method(:foo) m.splat_args? #=> false m.proc? #=> false args = m.arguments #=> [ Proc ] args.first.call #=> 3 would be nicer to work with, for me at least.