Skip to content

Instantly share code, notes, and snippets.

@enebo
Last active August 29, 2015 14:14
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 enebo/bcba5f4159314ddfdbcb to your computer and use it in GitHub Desktop.
Save enebo/bcba5f4159314ddfdbcb to your computer and use it in GitHub Desktop.
class Foo
def to_hash
1
end
end
foo = Foo.new
r1kr1 = proc { |a, b:| [a, b] }
p r1kr1.call(1, b: 2)
begin
r1kr1.call(1)
rescue # #<ArgumentError: missing keyword: b>
p $!
end
begin
r1kr1.call(1, foo)
rescue # #<TypeError: can't convert Foo to Hash (Foo#to_hash gives Fixnum)>
p $!
end
p r1kr1.call(1, {b: 2}, 3, {b: 6})
r1ko1 = proc { |a, b: 2| [a, b] }
p r1ko1.call(1, b: 3)
p r1ko1.call(1)
# If required or optional or rest kwargs we potentially can have one
# more parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment