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, #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

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

#inspectObject



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