Class: PatternMatch::PatternCondition
Instance Attribute Summary
Attributes inherited from Pattern
#next, #parent, #prev
Instance Method Summary
collapse
#quantifier?
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #vars, #|
#choice_points
Constructor Details
Returns a new instance of PatternCondition.
451
452
453
454
|
# File 'lib/pattern-match/core.rb', line 451
def initialize(&condition)
super()
@condition = condition
end
|
Instance Method Details
470
471
472
|
# File 'lib/pattern-match/core.rb', line 470
def inspect
"#<#{self.class.name}: condition=#{@condition.inspect}>"
end
|
#match(vals) ⇒ Object
456
457
458
459
460
461
462
463
|
# File 'lib/pattern-match/core.rb', line 456
def match(vals)
return false unless vals.empty?
if @condition.call
@next ? @next.match(vals) : true
else
false
end
end
|
465
466
467
468
|
# File 'lib/pattern-match/core.rb', line 465
def validate
super
raise MalformedPatternError if ancestors.find {|i| i.next and ! i.next.kind_of?(PatternCondition) }
end
|