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



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

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

#eql?(other) ⇒ Boolean



82
83
84
85
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 82

def eql?(other)
  return false unless other.is_a?(self.class)
  @__set.eql?(other.instance_variable_get(:@__set))
end

#freezeObject



56
57
58
59
60
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 56

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

#initialize_clone(orig) ⇒ Object



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

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

#initialize_dup(orig) ⇒ Object



87
88
89
90
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 87

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

#merge(other) ⇒ Object

Raises:

  • (ArgumentError)


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

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



97
98
99
100
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 97

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