Created
September 30, 2012 08:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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