From: Ross Bamford Date: 2006-05-08T23:37:41+09:00 Subject: Re: Raw idea about Proc On Mon, 2006-05-08 at 23:07 +0900, Victor Shepelev wrote: > Hi all. > > There is the idea (in VERY dirty code): > -- > class Proc > def bound; @bound ||= {} end > def bind(num, val) > bound[num - 1] = val > end > > alias :old_arity :arity > def arity > old_arity - bound.size > end > > alias :old_call :call > def call(*arg) > bound.to_a.reverse_each{|num, val| arg.insert(num, val)} > old_call(*arg) > end > end There are a few drawbacks to this approach I think, most of which I forget right now. A probable biggie is that it won't work with yield: l = lambda { |num,ele| p num, ele } l.bind(0,10) [1,2].each &l # 1 # nil # 2 # nil Maybe check out http://rubymurray.rubyforge.org , which does similar stuff but by wrapping up the proc (still has limitations, but there you go...) -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk