Skip to content

Instantly share code, notes, and snippets.

@0xGGGGG
Last active December 12, 2015 08:38
Show Gist options
  • Save 0xGGGGG/4745110 to your computer and use it in GitHub Desktop.
Save 0xGGGGG/4745110 to your computer and use it in GitHub Desktop.
keyword arguments is coming with ruby 2.0 . No need to merge stuff!
# In ruby < 2.0 we should implement this on our own.
def something_useful(opts = {})
opts = opts.merge({ overridden_opt: :something, another_overridden_opt: :something_else })
do_something_useful_with(opts[:overridden_opt]) if suitable?(opts[:another_overridden_opt])
end
# In new ruby 2.0 we can implement this behavior easily thanks to keyword_arguments.
def something_useful_and_makes_sense(opt: :something, another_opt: :something_else)
do_some_thing_useful_with(opt) if suitable?(another_opt)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment