From: nvp Date: 2008-11-02T03:25:06+09:00 Subject: Re: lambda and multiple arguments: how?! On Wed, Oct 29, 2008 at 6:41 AM, Robert Klemme wrote: > > You need to adjust the parameter list to the arity of the block. > Here's a way how to do it > > 11:38:30 Temp$ cat lambda.rb > @code = lambda {|a,b,c| printf "R: %p %p %p\n",a,b,c} > def run1(*params) [snip] Ah, I get it now! Took awhile to digest but this was perfect (checking arity and reassigning params based on value of arity - array.size was the key to the whole thing). Thanks! > Btw, IMHO you have a slight design inconsistency in your code: the > client registers a lambda with a certain pid so it *knows* the pid > already. But still you provide it to the block when calling it. That > seems superfluous because even if the pid is stored in a local > variable the block can access it because it is a closure: I fixed my code as a result so pid is no longer an argument in said functions. As it turns out, having pid as an argument was ambiguous as far as Ruby/lambda was concerned and it made reassigning params far too difficult. Since I was already assigning item[pid] = code, I merely checked for item[params[0]] before doing the obj.call(*params) and raising an error if item[params[0]] didn't exist. -- nvp "Of course, the US has many elements of socialism already since capitalists, like cats, tend to get themselves stuck up a tree every so often." -- Joe Johnston