Skip to content

Instantly share code, notes, and snippets.

@pabloh
Last active December 14, 2015 15:28
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 pabloh/5107526 to your computer and use it in GitHub Desktop.
Save pabloh/5107526 to your computer and use it in GitHub Desktop.
Keyword arguments on Ruby 2.0
# Ruby 2.0.0 is needed for the following code to work
def foo value, **keywords
puts [value,keywords].inspect
end
foo("somthing") #This works
foo("somthing", key: 'value') #This also works
foo(Hash.new(something: 'else')) #This raises 'ArgumentError: wrong number of arguments (0 for 1)'
class MyDirectory < Hash; end
foo(MyDirectory.new(something: 'else')) #This also raises 'ArgumentError: wrong number of arguments (0 for 1)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment