Last active
December 12, 2015 08:38
-
-
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!
This file contains hidden or 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
# 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