Class: Sexpr::Matcher::Alternative
- Inherits:
-
Object
- Object
- Sexpr::Matcher::Alternative
- Includes:
- Sexpr::Matcher
- Defined in:
- lib/sexpr/matcher/alternative.rb
Instance Attribute Summary collapse
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #eat(sexp) ⇒ Object
-
#initialize(terms) ⇒ Alternative
constructor
A new instance of Alternative.
- #inspect ⇒ Object
- #match?(sexp) ⇒ Boolean
Methods included from Sexpr::Matcher
Constructor Details
#initialize(terms) ⇒ Alternative
Returns a new instance of Alternative.
8 9 10 |
# File 'lib/sexpr/matcher/alternative.rb', line 8 def initialize(terms) @terms = terms end |
Instance Attribute Details
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
6 7 8 |
# File 'lib/sexpr/matcher/alternative.rb', line 6 def terms @terms end |
Instance Method Details
#eat(sexp) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sexpr/matcher/alternative.rb', line 16 def eat(sexp) @terms.each do |alt| res = alt.eat(sexp) return res if res end nil end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/sexpr/matcher/alternative.rb', line 24 def inspect "(alt #{terms.inspect})" end |
#match?(sexp) ⇒ Boolean
12 13 14 |
# File 'lib/sexpr/matcher/alternative.rb', line 12 def match?(sexp) terms.any?{|t| t.match?(sexp)} end |