Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

==/equal? overrides not used when checking keys #85

Open
renaudpr opened this issue Sep 1, 2023 · 0 comments
Open

==/equal? overrides not used when checking keys #85

renaudpr opened this issue Sep 1, 2023 · 0 comments

Comments

@renaudpr
Copy link

renaudpr commented Sep 1, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant