Today I Learned

Named arguments in Ruby

Using Ruby’s keyword arguments you can avoid the pitfalls of positional arguments as well as the extra code needed to extract values from a hash.

def total(subtotal:, tax:, discount:)
    subtotal + tax - discount
end

Default values can be provided if a named argument is not given to a method call.

def total(subtotal: 0, tax: 0, discount: 0)
  subtotal + tax - discount
end