Class: ANSI::Match

Inherits:
Object show all
Defined in:
lib/ansi/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Match

Returns a new instance of Match.



24
25
26
27
28
# File 'lib/ansi/match.rb', line 24

def initialize(*args)
  args.flatten!
  @args = args
  @codes = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/ansi/match.rb', line 3

def args
  @args
end

#codesObject (readonly)

Returns the value of attribute codes.



3
4
5
# File 'lib/ansi/match.rb', line 3

def codes
  @codes
end

Instance Method Details

#<<(code) ⇒ Object

Shorthand for adding an ANSI::Code to the #codes array.



31
32
33
# File 'lib/ansi/match.rb', line 31

def <<(code)
  @codes << code
end

#==(other) ⇒ Object

An object is considered to be equal to an ANSI::Match if:

  • it is an instance of ANSI::Match and both its arguments and relevant instances of ANSI::Code are equal.

  • it is an instance of ANSI::Code which is contained in the #codes array of this ANSI::Match.



8
9
10
11
12
13
14
15
16
# File 'lib/ansi/match.rb', line 8

def ==(other)
  if other.kind_of?(ANSI::Match)
    other.codes == @codes && other.args == @args
  elsif other.kind_of?(ANSI::Code)
    @codes.include?(other)
  else
    false
  end
end

#inspectObject Also known as: to_s



18
19
20
# File 'lib/ansi/match.rb', line 18

def inspect
  "#<ANSI::Match(#{@codes.join("|")}) args=#{@args.inspect}>"
end