Skip to content

Instantly share code, notes, and snippets.

@JulianKniephoff
Created September 30, 2012 08:23
Show Gist options
  • Save JulianKniephoff/3806245 to your computer and use it in GitHub Desktop.
Save JulianKniephoff/3806245 to your computer and use it in GitHub Desktop.
A very readable way to define default keyword style options to a method in Ruby.
module Kernel
# Define default options for a method.
#
# def foo(bar, options = {})
# default options, baz: "qux"
# end
def default(options, default_options)
options.replace(default_options.merge(options))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment