Class: PatternMatch::PatternSequence::PatternRewind

Inherits:
PatternMatch::PatternElement show all
Defined in:
lib/pattern-match/core.rb

Instance Attribute Summary collapse

Attributes inherited from PatternMatch::Pattern

#next, #parent, #prev

Instance Method Summary collapse

Methods inherited from PatternMatch::PatternElement

#quantifier?

Methods inherited from PatternMatch::Pattern

#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|

Methods included from PatternMatch::Pattern::Backtrackable

#choice_points

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

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

#inspectObject



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