From: ruby-core@... Date: 2016-11-25T22:05:31+00:00 Subject: [ruby-core:78366] [Ruby trunk Bug#12970] == Equality of recursive sets fails Issue #12970 has been updated by Marc-Andre Lafortune. Took me a while to understand what was going on. The issue is that the Set would need to be rehashed. Indeed, when you add it to itself, the element you are adding is modified too. This is, in a way, similar to: ``` a = [] s = Set.new(a) a << 42 s == Set.new([42]) # => false ``` If you add the following (horrible) two lines of code before calling `test`, the comparison works: ``` recursive_set_1.instance_variable_get(:@hash).rehash recursive_set_2.instance_variable_get(:@hash).rehash ``` Sadly, there is not (yet) a `Set#rehash` method. Original request for it by yours truly: check #6589... ---------------------------------------- Bug #12970: == Equality of recursive sets fails https://bugs.ruby-lang.org/issues/12970#change-61734 * Author: Kevin de Berk * Status: Open * Priority: Normal * Assignee: * ruby -v: 2.2.5, 2.3.3 * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- Comparing recursive arrays and hashes with equal? contents (save for the recursive element) using == succeeds. However, using == to compare two recursive sets with equal? contents fails. I expect that to succeed. See the attached script. This is my output for 2.2.5 and 2.3.3: ~~~ [1, 2, 3] == [1, 2, 3]? -> true [1, 2, 3, [...]] == [1, 2, 3, [...]]? -> true {:a=>1, :b=>2} == {:a=>1, :b=>2}? -> true {:a=>1, :b=>2, :c=>{...}} == {:a=>1, :b=>2, :c=>{...}}? -> true # == #? -> true # == #? -> false ~~~ ---Files-------------------------------- recursive_set_comparison.rb (871 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: