Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created February 19, 2015 15:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEG2/9b2bd99a31bcbcbf273a to your computer and use it in GitHub Desktop.
Save JEG2/9b2bd99a31bcbcbf273a to your computer and use it in GitHub Desktop.
Is this a bug in Ruby or just a poor method definition on my part?
class HashLike
def to_hash
{a: 1, b: 2}
end
end
def surprise(*args, keyword: nil)
p args
end
surprise(HashLike.new)
# ~> -:11:in `<main>': unknown keywords: a, b (ArgumentError)
@nathanl
Copy link

nathanl commented Feb 19, 2015

I'm even surprised at a simpler case; the fact that it calls to_hash at all.

class HashLike
  def to_hash
    {a: 1, b: 2}
  end
end
def return_keywords(one: 1, two: 2)
  [one, two]
end
return_keywords(HashLike.new)
# ~> ArgumentError: unknown keywords: a, b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment