Skip to content

Instantly share code, notes, and snippets.

@ciscou
Last active August 29, 2015 14:04
Show Gist options
  • Save ciscou/af98d6f71c8cc3b11ef1 to your computer and use it in GitHub Desktop.
Save ciscou/af98d6f71c8cc3b11ef1 to your computer and use it in GitHub Desktop.
ruby 2.0 keyword arguments
2.0.0-p451 :016 > def omg(foo: 42, bar: "hello world!")
2.0.0-p451 :017?> puts [foo, bar].inspect
2.0.0-p451 :018?> end
=> nil
2.0.0-p451 :019 > omg
[42, "hello world!"]
=> nil
2.0.0-p451 :020 > omg(1, "one")
ArgumentError: wrong number of arguments (2 for 0)
from (irb):16:in `omg'
from (irb):20
from /Users/francis/.rvm/rubies/ruby-2.0.0-p451/bin/irb:12:in `<main>'
2.0.0-p451 :021 > omg(foo: 1, bar: "one")
[1, "one"]
=> nil
2.0.0-p451 :022 > omg(zzz: "error!")
ArgumentError: unknown keyword: zzz
from (irb):22
from /Users/francis/.rvm/rubies/ruby-2.0.0-p451/bin/irb:12:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment