From: Peter Zotov Date: 2011-10-31T14:45:56+09:00 Subject: Re: How to save method signature while wrapping it? Alexey Petrushin писал 30.10.2011 22:42: > Hello, it would be interesting to automatically destruct hashes into > named method arguments, Ruby has the Method.parameters method: > > class A > def my_method a, b, c = 10; end > p instance_method(:my_method).parameters > # ==> [[:req, :a], [:req, :b], [:opt, :c]] > end > > (snip) > > So, I'm wondering, maybe there's some way to wrap method and still > preserve its signature? > > Basically attribute names are available (from method.parameters), but > I > don't know how to express named attributes in > block signature, i.e. - how to dynamically write `... do |args[1], > args[2], args[3]|` instead of `... do |*args|` (without eval of > course > :) ). I'd say that in this case `eval' is fine: the environment is controlled, and the code being generated is very deterministic. On any sane implementstion, after the parsing step this code will be absolutely equivalent to "properly"-defined one, and the parsing delay is negligible. -- WBR, Peter Zotov.