Skip to content

Instantly share code, notes, and snippets.

@taq
Created November 3, 2012 18:53
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 taq/4008264 to your computer and use it in GitHub Desktop.
Save taq/4008264 to your computer and use it in GitHub Desktop.
Ruby 2.0 keyword arguments
def foo(str: "foo", num: 123456)
[str, num]
end
p foo(str: 'buz', num: 9) #=> ['buz', 9]
p foo(str: 'bar') # => ['bar', 123456]
p foo(num: 123) # => ['foo', 123]
p foo # => ['foo', 123456]
p foo(bar: 'buz') # => ArgumentError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment