Method: Weak::Set#==

Defined in:
lib/weak/set.rb

#==(other) ⇒ Bool

Returns true if two weak sets are equal. The equality of each couple of elements is defined according to strict object equality so that, e.g., different strings are not equal, even if they may contain the same data.

Examples:

Weak::Set[1, 2] == Weak::Set[2, 1]         #=> true
Weak::Set[1, 3, 5] == Weak::Set[1, 5]      #=> false
Weak::Set[1, 2, 3] == [1, 3, 2]            #=> false

Parameters:

  • other (Weak::Set)

    a weak set to compare to self

Returns:

  • (Bool)

    true if the other object is a weak set containing exactly the same elements as self, false otherwise


335
336
337
338
339
340
341
342
343
344
# File 'lib/weak/set.rb', line 335

def ==(other)
  return true if equal?(other)
  return false unless Weak::Set === other

  other_ary = other.to_a
  own_ary = to_a

  return false unless own_ary.size == other_ary.size
  own_ary.all?(other)
end