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, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|
Constructor Details
#initialize(ntimes, head_pattern, next_pattern) ⇒ PatternRewind
Returns a new instance of PatternRewind.
365 366 367 368 369 370 |
# File 'lib/pattern-match/core.rb', line 365 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.
363 364 365 |
# File 'lib/pattern-match/core.rb', line 363 def ntimes @ntimes end |
Instance Method Details
#inspect ⇒ Object
381 382 383 |
# File 'lib/pattern-match/core.rb', line 381 def inspect "#<#{self.class.name}: ntimes=#{@ntimes} head=#{@head.inspect} next=#{@next.inspect}>" end |
#match(vals) ⇒ Object
372 373 374 375 376 377 378 379 |
# File 'lib/pattern-match/core.rb', line 372 def match(vals) if @ntimes > 0 @ntimes -= 1 @head.match(vals) else @next ? @next.match(vals) : vals.empty? end end |