On Thu, Dec 4, 2008 at 08:01, Paul McMahon <paul.mcmahon / ubit.com> wrote:
> 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]

Actually, it returns [:opt, param_name, default_value], but default
values are only given for basic types (Numerics, Symbols, true, false
and nil, that I could see) anyway. For your example, it would return
just [[:opt, :foo]], no third element on the Array.

> 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.

As some already mentioned, a Proc would not work, because a default
value has a very particular binding: it runs in the context of the
receiver, and can reference all the parameters that come before
itself.

For example:

    def f(x, y = x * 2, z = x + y, w = some_private_method); end

--
Daniel