From: Jos Backus Date: 2007-03-22T12:26:01+09:00 Subject: Re: Ruby Method Signatures (was Re: Multiton in standard library) On Thu, Mar 22, 2007 at 10:52:56AM +0900, TRANS wrote: > On 3/21/07, Jos Backus wrote: > >On 3/19/07, TRANS wrote: [snip] > I'm a little confused, What's output of this? It prints a suitably indented execution trace showing caller and arguments/return values. > This maybe completely aside, but the above reminds me that with > 'this', there could be: > > def(a,b) > Trace.begin(*this.arguments) > end > > Basically args irregardless of the the actual signature. > > As for the signature, it would have to be a special class of object > that has the qualities of Ruby's arguments -- the ordered list, the > default params and etc. With that object a few things could be > queried, such as arity, maybe a list of parameter names, whether it > has a * parameter or a &block parameter, etc. Importantly it could > output a string representation or the args (whether with the original > names or not). Eg. > > def a(x,y) > this.signature.to_s #=> "x,y" -or- "a1,a2" > > A bonus would be to use the arguments in place of actual arguments > when defining a method. > > def foo(x) > end > > def bar(*=method(:foo).signature) > p x # or p a1 > end > > bar(1) #=> 1 > > The *= is needed b/c there has to a special way to indicate that. > > T. This looks neat. But I'm worried about the potential overhead this could introduce. -- Jos Backus jos at catnook.com