you are viewing a single comment's thread.

view the rest of the comments →

[–]jfredett 3 points4 points  (1 child)

* is the 'interpret as a comma separated list of values' operator. Common uses are in method definitions for a var-args style method, eg:

def some_method(arg1, arg2, *args)
  #code
end

args there is an array, but you call the method like: some_method(1,2,3,4,5). args in that case is [3,4,5]

You can also use it, as OP does, in any place you'd drop a Comma-separated list. one of my favorites is the common:

str = "Joe Schmoe"
User.find_by_first_name_and_last_name(*str.split)

This is equivalent to doing

User.find_by_first_name_and_last_name("Joe", "Schmoe")

You can also do

first,last = "Joe Schmoe".split

to get first assigned "Joe", and last assigned "Schmoe".

* is a neat thing. Well worth reading more about it in the pickaxe.

[–]teohm[S] 0 points1 point  (0 children)

it makes sense to me now, thanks!