hashdiff icon indicating copy to clipboard operation
hashdiff copied to clipboard

==/equal? overrides not used when checking keys

Open renaudpr opened this issue 1 year ago • 0 comments

Hello, The override of the ==/equal? methods seem to be used when checking values of an Hash, but not when checking the keys. Here is an example with a simple class :

class Color
  attr_reader :value

  def initialize(value)
    @value = value
  end

  def equal?(other)
    return false unless other.is_a?(Color)

    @value == other.value
  end

  def ==(other)
    return false unless other.is_a?(Color)

    @value == other.value
  end
end

Hashdiff.best_diff({1 => Color.new('red')}, {1 => Color.new('red')}) returns [] as expected but Hashdiff.best_diff({Color.new('red') => 1}, {Color.new('red') => 1}) returns [["~", "#<Color:0x000014ac0e49d418>", 1, nil]]

Thanks!

renaudpr avatar Sep 01 '23 09:09 renaudpr