Skip to content

Instantly share code, notes, and snippets.

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