Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created February 6, 2014 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/8843215 to your computer and use it in GitHub Desktop.
Save workmad3/8843215 to your computer and use it in GitHub Desktop.
def foo(options={})
default_options = {
foo: "bar"
}
options = options.dup
options.default_proc = proc{|h,k| default_options[k] || (raise ArgumentError.new("No value for required option #{k}"))}
# Now access options as 'normal'
puts options[:foo]
puts options[:bar]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment