Skip to content

Instantly share code, notes, and snippets.

@bryanp
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save bryanp/b729fb5e5674b5b5d374 to your computer and use it in GitHub Desktop.

Select an option

Save bryanp/b729fb5e5674b5b5d374 to your computer and use it in GitHub Desktop.
Perplexing Keyword Args
class MM
def method_missing(method, *args, **kargs)
puts method.inspect
puts args.inspect
puts kargs.inspect
end
end
MM.new.foo({ foo: 'bar' }, one: 1)
# => :foo
# [{:foo=>"bar"}]
# {:one=>1}
MM.new.foo({ foo: 'bar' })
# => :foo
# []
# {:foo=>"bar"}
# In the second case, I would expect the hash to be the first `arg` and `kargs`to be an empty hash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment