class Persistent💎::Set

Public Class Methods

from_set(set) click to toggle source
# File lib/persistent_dmnd/set.rb, line 49
def self.from_set(set)
  self[*set.to_a]
end

Public Instance Methods

<=>(other) click to toggle source

Note: Behavior changed from Ruby < 3 (returned 0/nil) to match Ruby 3.0 Set#<=> (returns 0/nil/-1/+1);

see also https://rubyreferences.github.io/rubychanges/3.0.html#standard-library for details
# File lib/persistent_dmnd/set.rb, line 70
def <=>(other)
  case size <=> other.size
  when (-1)
    (-1) if self < other
  when (+1)
    (+1) if self > other
  else
    0 if self == other
  end
end
==(other) click to toggle source
Calls superclass method
# File lib/persistent_dmnd/set.rb, line 53
def ==(other)
  super || other.respond_to?(:to_set) && set_eq?(other.to_set)
end
is_a?(klass) click to toggle source
Calls superclass method
# File lib/persistent_dmnd/set.rb, line 57
def is_a?(klass)
  super ||
    # hack to allow Set to be comparable with us
    # and yes a Persistent💎::Set is a Set: go away, stop type-checking and start duck typing!
    klass == ::Set
end
to_aDmnd()
Alias for: to_a💎
to_a💎() click to toggle source
# File lib/persistent_dmnd/set.rb, line 81
def to_a💎
  a💎[*self]
end
Also aliased as: to_aDmnd
to_hDmnd()
Alias for: to_h💎
to_h💎() click to toggle source
# File lib/persistent_dmnd/set.rb, line 87
def to_h💎
  h💎[self]
end
Also aliased as: to_hDmnd
to_sDmnd()
Alias for: to_s💎
to_set() click to toggle source
# File lib/persistent_dmnd/set.rb, line 64
def to_set
  ::Set.new(self)
end
to_s💎() click to toggle source
# File lib/persistent_dmnd/set.rb, line 93
def to_s💎
  self
end
Also aliased as: to_sDmnd

Private Instance Methods

set_eq?(other) click to toggle source
# File lib/persistent_dmnd/set.rb, line 101
def set_eq?(other)
  self.size == other.size && other.all? { |item| include?(item) }
end