Open
Description
On Hamster's Hamster.from
documentation, there's no mention that Struct
will be converted to a hash, and indeed it is really strange:
class SomeClass < Struct.new(:foo, :bar); end
obj = SomeClass.new(10, 20)
irb(main):014:0> Hamster.from({obj: obj})
# => Hamster::Hash[:obj => Hamster::Hash[:bar => 20, :foo => 10]]
The problem is that SomeClass
is not a hash, it is a struct, so this will fail:
a = {obj: SomeClass.new(10, 20)}
b = {obj: SomeClass.new(10, 20)}
Hamster.to_ruby(Hamster.from(a)) == b
# => false
# While these are true:
a == b
Hamster.to_ruby(Hamster.from(a)) == Hamster.to_ruby(Hamster.from(b))
The problem is that Hamster.from
loses the struct information, so it's impossible to get back the original object, and the documentation doesn't mention anything.
Metadata
Metadata
Assignees
Labels
No labels