Class: Regexgen::Ast::Alternation
- Inherits:
-
Object
- Object
- Regexgen::Ast::Alternation
- Defined in:
- lib/regexgen/ast.rb
Overview
Represents an alternation (e.g. ‘foo|bar`)
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
Instance Method Summary collapse
-
#initialize(*options) ⇒ Alternation
constructor
A new instance of Alternation.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*options) ⇒ Alternation
Returns a new instance of Alternation.
10 11 12 13 |
# File 'lib/regexgen/ast.rb', line 10 def initialize(*) @precedence = 1 = flatten().sort { |a, b| b.length - a.length } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/regexgen/ast.rb', line 8 def end |
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence.
8 9 10 |
# File 'lib/regexgen/ast.rb', line 8 def precedence @precedence end |
Instance Method Details
#length ⇒ Object
15 16 17 |
# File 'lib/regexgen/ast.rb', line 15 def length [0].length end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/regexgen/ast.rb', line 19 def to_s .map { |o| Ast.parens(o, self) }.join('|') end |