Hi,
I want to pass an array into a block like so
v2 = []
object.some_method_that_takes_a_block do | v1, v2|
v2.push v1.action
end
causes a undefined method push for nil
the problem is that v2 gets assigned as nil as it gets passed through, is there any way around this?
I don't really want to open the original class and try to add a new method signature (I hope that's not how to get it to accept to variables)
Kev
Hi,
Have you tried:
v2 = []
object.some_method_that_takes_a_block do | v1 |
v2.push v1.action
end
Regards,
Peter
You're not actually "passing" v2 anywhere. The |v1, v2| creates two
variables, v1 and v2, local to that block. It's the method itself that
supplies the values of v1 and v2. Are you sure what you're trying to
do is correct?
···
On 11/4/05, Kev Jackson <kevin.jackson@it.fts-vn.com> wrote:
Hi,
I want to pass an array into a block like so
v2 =
object.some_method_that_takes_a_block do | v1, v2|
v2.push v1.action
end
causes a undefined method push for nil
the problem is that v2 gets assigned as nil as it gets passed through,
is there any way around this?
I don't really want to open the original class and try to add a new
method signature (I hope that's not how to get it to accept to variables)
Kev
Peter C. Verhage wrote:
Hi,
Have you tried:
v2 =
object.some_method_that_takes_a_block do | v1 |
v2.push v1.action
end
Regards,
Peter
DOH!
Sorry all, that was really #*&(^)@ dumb of me
Thanks for the clue
Kev
Hi --
You're not actually "passing" v2 anywhere. The |v1, v2| creates two
variables, v1 and v2, local to that block. It's the method itself that
supplies the values of v1 and v2. Are you sure what you're trying to
do is correct?
It's a little different than that: at the time of |v1,v2| v2 already
exists, since it was created before the block. So the overall effect
is like:
v2 =
v1, v2 = some_scalar_value
which reassigns nil to v2.
David
···
On Fri, 4 Nov 2005, Daniel Wislocki wrote:
On 11/4/05, Kev Jackson <kevin.jackson@it.fts-vn.com> wrote:
Hi,
I want to pass an array into a block like so
v2 =
object.some_method_that_takes_a_block do | v1, v2|
v2.push v1.action
end
causes a undefined method push for nil
the problem is that v2 gets assigned as nil as it gets passed through,
is there any way around this?
I don't really want to open the original class and try to add a new
method signature (I hope that's not how to get it to accept to variables)
Kev
--
David A. Black
dblack@wobblini.net