Class: PatternMatch::PatternSequence::PatternRewind
- Inherits:
-
PatternMatch::PatternElement
- Object
- PatternMatch::Pattern
- PatternMatch::PatternElement
- PatternMatch::PatternSequence::PatternRewind
- Defined in:
- lib/pattern-match/core.rb
Instance Attribute Summary collapse
-
#ntimes ⇒ Object
readonly
Returns the value of attribute ntimes.
Attributes inherited from PatternMatch::Pattern
Instance Method Summary collapse
-
#initialize(ntimes, head_pattern, next_pattern) ⇒ PatternRewind
constructor
A new instance of PatternRewind.
- #inspect ⇒ Object
- #match(vals) ⇒ Object
Methods inherited from PatternMatch::PatternElement
Methods inherited from PatternMatch::Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|
Methods included from PatternMatch::Pattern::Backtrackable
Constructor Details
#initialize(ntimes, head_pattern, next_pattern) ⇒ PatternRewind
Returns a new instance of PatternRewind.
320 321 322 323 324 325 |
# File 'lib/pattern-match/core.rb', line 320 def initialize(ntimes, head_pattern, next_pattern) super() @ntimes = ntimes @head = head_pattern @next = next_pattern end |
Instance Attribute Details
#ntimes ⇒ Object (readonly)
Returns the value of attribute ntimes.
318 319 320 |
# File 'lib/pattern-match/core.rb', line 318 def ntimes @ntimes end |
Instance Method Details
#inspect ⇒ Object
336 337 338 |
# File 'lib/pattern-match/core.rb', line 336 def inspect "#<#{self.class.name}: ntimes=#{@ntimes} head=#{@head.inspect} next=#{@next.inspect}>" end |
#match(vals) ⇒ Object
327 328 329 330 331 332 333 334 |
# File 'lib/pattern-match/core.rb', line 327 def match(vals) if @ntimes > 0 @ntimes -= 1 @head.match(vals) else @next ? @next.match(vals) : vals.empty? end end |