Created
May 16, 2016 12:12
-
-
Save thorstenhirsch/30d305f553d5c5a30201308421a4e2fe to your computer and use it in GitHub Desktop.
method call with hash and key-value params
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
# 1) | |
something({id: 1, foo: 'bar'}, to: 'me') | |
# 2) | |
something(id: 1, foo: 'bar', to: 'me') | |
# how can somthing support both calls whilst to: is an optional parameter? | |
def something(*args, to: nil, **opts) | |
msg = {} | |
msg.merge!(opts) | |
args.each {|a| msg.merge!(a) if a.is_a? Hash} | |
puts "to: #{to}" | |
puts "everything else: #{msg}" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment