Issue #16690 has been updated by byroot (Jean Boussier).


That's explained in the documentation of the class: https://ruby-doc.org/stdlib-2.7.0/libdoc/set/rdoc/Set.html

> Set uses Hash as storage, so you must note the following points:


> Set assumes that the identity of each element does not change while it is stored. **Modifying an element of a set will render the set to an unreliable state.**

----------------------------------------
Bug #16690: [BUG] Set of sets: containing set no longer believes member set is a member after mutating its member set
https://bugs.ruby-lang.org/issues/16690#change-84599

* Author: keithyjohnson (Keith Johnson)
* Status: Open
* Priority: Normal
* ruby -v: 2.3.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Please correct me if I'm wrong but I expected that when mutating a member set of a containing set, that that mutated member set, would still be considered a member of the containing set.  But after merging another set into the member set, the containing set no longer believes it to be a member.  I was surprised by this, but if that is expected behavior, please let me know!  Also, please let me know if you have any more questions.

``` ruby
[1] pry(#<Clustering>)> clusters.class
=> Set
[2] pry(#<Clustering>)> smaller_cluster.class
=> Set
[3] pry(#<Clustering>)> larger_cluster.class
=> Set
[4] pry(#<Clustering>)> x = larger_cluster.object_id
=> 70237123254460
[5] pry(#<Clustering>)> clusters.member?(larger_cluster)
=> true
[6] pry(#<Clustering>)> larger_cluster.merge(smaller_cluster)
=> #<Set: {387, 92}>
[7] pry(#<Clustering>)> larger_cluster.object_id == x
=> true
[8] pry(#<Clustering>)> clusters.member?(larger_cluster)
=> false
[9] pry(#<Clustering>)> clusters.map(&:object_id).include?(larger_cluster.object_id)
=> true
[10] pry(#<Clustering>)> RUBY_VERSION
=> "2.3.0"
```





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>