Module: CharacterSet::RubyFallback::SetMethods

Included in:
CharacterSet::RubyFallback
Defined in:
lib/character_set/ruby_fallback/set_methods.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 72

def ==(other)
  if equal?(other)
    true
  elsif other.instance_of?(self.class)
    @__set == other.instance_variable_get(:@__set)
  elsif other.is_a?(CharacterSet) || other.is_a?(CharacterSet::Pure)
    size == other.size && other.all? { |cp| @__set.include?(cp) }
  else
    false
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 84

def eql?(other)
  return false unless other.is_a?(self.class)
  # revert if https://github.com/knu/sorted_set/issues/3 is resolved
  hash == other.hash
end

#freezeObject



58
59
60
61
62
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 58

def freeze
  @__set.to_a
  @__set.freeze
  super
end

#hashObject

revert if github.com/knu/sorted_set/issues/3 is resolved



91
92
93
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 91

def hash
  @__set.to_a.hash
end

#initialize_clone(orig) ⇒ Object



100
101
102
103
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 100

def initialize_clone(orig)
  super
  @__set = orig.instance_variable_get(:@__set).clone
end

#initialize_dup(orig) ⇒ Object



95
96
97
98
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 95

def initialize_dup(orig)
  super
  @__set = orig.instance_variable_get(:@__set).dup
end

#merge(other) ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
69
70
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 65

def merge(other)
  raise ArgumentError, 'pass an Enumerable' unless other.respond_to?(:each)
  # pass through #add to use the checks in SetMethodAdapters
  other.each { |e| add(e) }
  self
end

#to_a(stringify = false) ⇒ Object



105
106
107
108
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 105

def to_a(stringify = false)
  result = @__set.to_a
  stringify ? result.map { |cp| cp.chr('utf-8') } : result
end