Last active
August 29, 2015 14:08
-
-
Save bryanp/b729fb5e5674b5b5d374 to your computer and use it in GitHub Desktop.
Perplexing Keyword Args
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
| 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