I’m not saying this is a bug, but I can’t explain this behavior. I’m
just looking for an explanation. If a method accepts a hash as its first
argument, and then one or more keyword arguments (with default values)
after that, the behavior is confusing. Calling the method with only a
single hash results in an unknown keyword
error. However, Calling the
method with a hash first, and then another hash for the keyword
arguments, works just fine.
GIST: keys.rb · GitHub
puts RUBY_VERSION
#=> "2.0.0"
def parameters(params={}, content_type: "text/html")
puts params
puts content_type
end
parameters({ query: "Ruby" })
#=> ArgumentError: unknown keyword: query
parameters({ query: "Ruby" }, { content_type: "application/json" })
#=> {:query=>"Ruby"}
#=> application/json
parameters({ query: "Ruby" }, {})
#=> {:query=>"Ruby"}
#=> text/html
Can someone point me to documentation for this behavior, or otherwise
explain why it happens this way? Thanks.