Argon2::Password.hash overrides Object#hash in an incompatible manner
dgutov opened this issue · 5 comments
dgutov commented
Which makes it impossible to use the class as a key in a hash, for instance:
$ irb
irb(main):001:0> require 'argon2'
=> true
irb(main):002:0> h = {}
=> {}
irb(main):003:0> h[Argon2::Password] = 42
ArgumentError: wrong number of arguments (0 for 1)
from /home/gutov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/argon2-0.1.4/lib/argon2.rb:25:in `hash'
from (irb):3
from /home/gutov/.rbenv/versions/2.1.2/bin/irb:11:in `<main>'technion commented
I could change the hash function to "create" in line with other similar gems. However, this would be a breaking change. Therefore I would have to ask, is the above code something you would ever write in practice?
dgutov commented
Yup. I use a hash to cache class names here: https://github.com/dgutov/robe/blob/master/lib/robe/sash.rb#L38
It's a dynamic code assistance tool.
technion commented
Sounds like I'm sold. Incoming fix.
technion commented
This requires an obvious version bump. I've done so in the source, I'll let it settle a few days before tagging a release.
dgutov commented
Thanks!