Class: Reginald::Character

Inherits:
String
  • Object
show all
Defined in:
lib/rack/mount/vendor/reginald/reginald/character.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ Character

Returns a new instance of Character.

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 5

def initialize(char)
  raise ArgumentError if char.length != 1
  super
end

Instance Attribute Details

#quantifierObject

Returns the value of attribute quantifier.



3
4
5
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 3

def quantifier
  @quantifier
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 34

def ==(other)
  case other
  when String
    other == to_s
  else
    eql?(other)
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 43

def eql?(other)
  other.is_a?(self.class) && super &&
    self.quantifier == other.quantifier
end

#freezeObject



48
49
50
51
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 48

def freeze
  quantifier.freeze
  super
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 30

def include?(char)
  to_str == char
end

#inspectObject



22
23
24
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 22

def inspect
  to_s.inspect
end

#literal?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 10

def literal?
  quantifier.nil?
end

#match(char) ⇒ Object



26
27
28
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 26

def match(char)
  to_regexp.match(char)
end

#to_regexpObject



18
19
20
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 18

def to_regexp
  Regexp.compile("\\A#{to_s}\\Z")
end

#to_sObject



14
15
16
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 14

def to_s
  "#{super}#{quantifier}"
end