Class: Lexeme::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/lexeme/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, regex) ⇒ Rule

Returns a new instance of Rule.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
# File 'lib/lexeme/rule.rb', line 5

def initialize(name, regex)
  raise ArgumentError, 'name must be a String or a Symbol' unless 
    name.nil? || name.is_a?(String) || name.is_a?(Symbol)
  raise ArgumentError, 'regex must be a Regex' unless 
    regex.is_a? Regexp
  
  @name  = name
  @regex = regex
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/lexeme/rule.rb', line 3

def name
  @name
end

#regexObject (readonly)

Returns the value of attribute regex.



3
4
5
# File 'lib/lexeme/rule.rb', line 3

def regex
  @regex
end