Hello,
Let’s say that I have created a proc like:
a = proc{ puts x } (NOT! a = proc{ |x| puts x })
In this case, x within the scope of the proc does not exist and proc ‘a’
is
unable to receive an argument to set it…
If I wanted to take proc ‘a’ and create another proc, which did include
arguments…
In fact, lets say I just wanted to grab an existing proc, modify the
parameters to include |*args|, knowing that within the existing proc, I
am
grabbing my passed variables from the args array, even though they, at
that
point, don’t exist…
I did find the ‘parameters’ method on Proc and I found that when a proc
has
arity of 0, parameters is an empty array, and then depending on the
argument, parameters will return something like [ [:opt, :x], [:opt, :y]
]
for |x, y| or [ [:rest, :args] ] for |*args|…
However, parameters, while it certain LOOKS like it is taking the values
if
I pass (<<) the appropriate values to it, they will not actually store.
I also played around a little bit with grabbing the binding of the proc
without parameters and then trying to create the required variables
within
that binding, but I didn’t try too hard which is probably why it didn’t
work, because in theory, that should be doable.
Is what I am attempting to do possible? Or is there a work-around that
isn’t too hacky?
Thanks in advance,
Daniel