Tuesday, August 14, 2012

Passing array of elements as multiple arguments in a ruby method

Suppose we wanna pass an array of elements like this

keys = %w{
  user_id
  shop_id
  url
  title
  shop_name
}

Then we need to prepend the variable with * as arguments

Shop.slice(*keys)

No comments: