But when might the 1st way (using the unary operator) be preferred to
the more explicit 2nd way?
Oops. Scratch that last question.
But when might the 1st way (using the unary operator) be preferred to
the more explicit 2nd way?
Oops. Scratch that last question.
Hi --
a = [1,2,3]
x(a) # [[1,2,3,]]
x(*a) # [1,2,3]x(*a) # [1,2,3]
x(a.to_a) # also [1,2,3]But when might the 1st way (using the unary operator) be preferred to
the more explicit 2nd way?
I did leave off the to_a, though array.to_a is a no-op so it shouldn't
matter.
More to the point: what version of Ruby are you using? Here's the
output with 1.8.3:
$ cat args2.rb
def x(*args)
p args
end
a = [1,2,3]
x(a.to_a)
x(*a)
$ ruby -v args2.rb ruby 1.8.3 (2005-09-21) [powerpc-darwin8.3.0]
[[1, 2, 3]]
[1, 2, 3]
David
On Fri, 2 Dec 2005, Brian Buckley wrote:
--
David A. Black
dblack@wobblini.net
Hi --
On Fri, 2 Dec 2005, Daniel Schierbeck wrote:
David A. Black wrote:
As Gary says it's actually to_a, not to_ary
#to_ary is called first; if it doesn't exist #to_a will be called.
Whoops -- I got a false negative on a (flawed) little test I ran.
David
--
David A. Black
dblack@wobblini.net
More to the point: what version of Ruby are you using? Here's the
output with 1.8.3:
I am an older version (1.8.2) but I am getting the same result as you.
I didn't realize you'd intentionally omitted to noop to_a. That and
with Ross's explanation, now I get it.