Module: CharacterSet::RubyFallback::SetMethods
- Included in:
- CharacterSet::RubyFallback
- Defined in:
- lib/character_set/ruby_fallback/set_methods.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #freeze ⇒ Object
- #initialize_clone(orig) ⇒ Object
- #initialize_dup(orig) ⇒ Object
- #merge(other) ⇒ Object
- #to_a(stringify = false) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 62 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
74 75 76 77 78 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 74 def eql?(other) return false unless other.is_a?(self.class) @__set.eql?(other.instance_variable_get(:@__set)) end |
#freeze ⇒ Object
48 49 50 51 52 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 48 def freeze @__set.to_a @__set.freeze super end |
#initialize_clone(orig) ⇒ Object
85 86 87 88 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 85 def initialize_clone(orig) super @__set = orig.instance_variable_get(:@__set).clone end |
#initialize_dup(orig) ⇒ Object
80 81 82 83 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 80 def initialize_dup(orig) super @__set = orig.instance_variable_get(:@__set).dup end |
#merge(other) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 55 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
90 91 92 93 |
# File 'lib/character_set/ruby_fallback/set_methods.rb', line 90 def to_a(stringify = false) result = @__set.to_a stringify ? result.map { |cp| cp.chr('utf-8') } : result end |