DEV Community

Discussion on: What does ** (two asterisks in a row) mean in Ruby?

Collapse
 
_swanand profile image
Swanand • Edited

It is also called double-splat operator, and can be used to apply named arguments to a method:


def add_name(first_name:, middle_name: nil, last_name:)
  pp [first_name, middle_name, last_name]
  # other code here
end

name_attributes = { first_name: "Mickey", last_name: "Mouse" }

add_name(**name_attributes)

# => ["Mickey", nil, "Mouse"]

Enter fullscreen mode Exit fullscreen mode