Class: Set
Overview
Override #== to fix behavior where it seems to ignore overrides of Object#== or Object#eql? when comparing set elements. Note that we can’t put these definitions inside a helper module, as we do for other methods, and include in the reopened Hash class. If we do this, the method is not used!
Instance Method Summary collapse
- #==(set) ⇒ Object (also: #eql?)
-
#intersection_using_eql_comparison(other) ⇒ Object
It seems that Set#& should work, but for some reason, it doesn’t.
-
#union_using_eql_comparison(other) ⇒ Object
It seems that Set#| should work, but for some reason, it doesn’t.
Instance Method Details
#==(set) ⇒ Object Also known as: eql?
7 8 9 10 11 12 |
# File 'lib/aquarium/extensions/set.rb', line 7 def == set equal?(set) and return true set.is_a?(Set) && size == set.size or return false ary = to_a set.all? { |o| ary.include?(o) } end |
#intersection_using_eql_comparison(other) ⇒ Object
It seems that Set#& should work, but for some reason, it doesn’t.
24 25 26 27 28 |
# File 'lib/aquarium/extensions/set.rb', line 24 def intersection_using_eql_comparison other first = dup second = other.dup first.size > second.size ? do_intersection(first, second) : do_intersection(second, first) end |
#union_using_eql_comparison(other) ⇒ Object
It seems that Set#| should work, but for some reason, it doesn’t.
17 18 19 20 21 |
# File 'lib/aquarium/extensions/set.rb', line 17 def union_using_eql_comparison other first = dup second = other.dup first.size > second.size ? do_union(first, second) : do_union(second, first) end |