Class: Sexpr::Matcher::Alternative

Inherits:
Object
  • Object
show all
Includes:
Sexpr::Matcher
Defined in:
lib/sexpr/matcher/alternative.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#termsObject (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

#inspectObject



24
25
26
# File 'lib/sexpr/matcher/alternative.rb', line 24

def inspect
  "(alt #{terms.inspect})"
end

#match?(sexp) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sexpr/matcher/alternative.rb', line 12

def match?(sexp)
  terms.any?{|t| t.match?(sexp)}
end