Skip to content

Instantly share code, notes, and snippets.

@bhuga
Created November 13, 2017 17:32
Show Gist options
  • Save bhuga/07e40e674518b8e2e4d46f77feb46e9f to your computer and use it in GitHub Desktop.
Save bhuga/07e40e674518b8e2e4d46f77feb46e9f to your computer and use it in GitHub Desktop.
is this a ruby bug or am i misunderstanding something? fails on 2.4.1p111
# without a default for x
def foo(x, keyword: :b)
puts x
puts keyword
end
foo({x: 1})
#{:x=>1}
#b
# make x's default an empty hash
def foo(x={}, keyword: :b)
puts x
puts keyword
end
foo({x: 1}, keyword: :c)
# {:x=>1}
# c
foo({x: 1})
# ArgumentError: unknown keyword: x
# Why raise? why assume the has is kwargs after giving x a default of {}?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment