From: Mark Bush Date: 2008-02-21T23:34:30+09:00 Subject: Re: What does *args do? > What does the *args do? Thanks! As well as the previously posted explanations of *args appearing in a method argument list, it can also appear in a method body. In that case, the array gets turned into a list. That is, if a = [1, 2, 3, 4] then you can use *a to represent the list of values (here 1, 2, 3, 4). This is useful for adding the values to an array: [5, *a] # => [5, 1, 2, 3, 4] [5, a] # => [5, [1, 2, 3, 4]] In Ruby 1.8 this can only be at the end of the array, but in 1.9 it can be anywhere: [*a, *a] # => [1, 2, 3, 4, 1, 2, 3, 4] (in 1.9) Also, if you want to pass the values as separate arguments to another method: puts *a # => same as: puts 1, 2, 3, 4 puts a # => same as: puts [1, 2, 3, 4] You can even do multiple assignment this way: b, c, d, e = *a b # => 1 c # => 2 d # => 3 e # => 4 Note that this works with hashes, too. If a is a hash, then *a is the equivalent of: b = a.to_a *b if you see what I mean. -- Posted via http://www.ruby-forum.com/.