*variable works in asssignment?

I was trying to figure out how to do the equivalent of (in Perl):

$one, $two, @rest = @ARGV

and it seems that I can do:

one, two, *rest = ARGV

in Ruby. However, I can’t see this documented anywhere (I looked in
the pickaxe, and in the manual shipped with Debian’s ruby-manual
package), and I wanted to make sure I could rely on it working in
future versions of Ruby.

I do see it used in method parameters:

def method(one,two,*rest)
#…
end

But nobody seems to say that you can do it generically in assignments,
and I’m always a tad nervous about using what appear to be
undocumented language features.

If this is documented, of course, a pointer to where would be nice.
Note: Source code doesn’t count. :slight_smile:

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton

Check out the Ruby FAQ at http://165.193.123.250/faq/rubyfaq.html
section 4.8

···

11/13/2002 1:18:06 PM, Eric Schwartz emschwar@fc.hp.com wrote:

I was trying to figure out how to do the equivalent of (in Perl):

$one, $two, @rest = @ARGV

and it seems that I can do:

one, two, *rest = ARGV

in Ruby. However, I can’t see this documented anywhere (I looked in
the pickaxe, and in the manual shipped with Debian’s ruby-manual
package), and I wanted to make sure I could rely on it working in
future versions of Ruby.

I do see it used in method parameters:

def method(one,two,*rest)
#…
end

But nobody seems to say that you can do it generically in assignments,
and I’m always a tad nervous about using what appear to be
undocumented language features.

If this is documented, of course, a pointer to where would be nice.
Note: Source code doesn’t count. :slight_smile:

-=Eric

Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton

If this is documented, of course, a pointer to where would be nice.
Note: Source code doesn’t count. :slight_smile:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UC

James

···

-=Eric