Skip to content

Instantly share code, notes, and snippets.

@thorstenhirsch
Created May 16, 2016 12:12
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 thorstenhirsch/30d305f553d5c5a30201308421a4e2fe to your computer and use it in GitHub Desktop.
Save thorstenhirsch/30d305f553d5c5a30201308421a4e2fe to your computer and use it in GitHub Desktop.
method call with hash and key-value params
# 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