Last active
August 29, 2015 14:08
-
-
Save bryanp/049ec81eb8a4dd353f49 to your computer and use it in GitHub Desktop.
WTF Keyword Args
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
class MM | |
def method_missing(method, *args, **kargs) | |
foo(*args) | |
end | |
end | |
def foo(data, one: 1) | |
end | |
MM.new.foo({ foo: 'bar' }, one: 1) | |
# works fine | |
MM.new.foo('bar') | |
# also works fine | |
MM.new.foo({ foo: 'bar' }) | |
# valid signature, but raises ArgumentError | |
# this is due to an edge-case with keyword args where if the last value | |
# in a method call is a hash the value is passed as keyword args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment