class SyntaxTree::YARV::CheckMatch

### Summary

‘checkmatch` checks if the current pattern matches the current value. It pops the target and the pattern off the stack and pushes a boolean onto the stack if it matches or not.

### Usage

~~~ruby foo in Foo ~~~

Constants

VM_CHECKMATCH_ARRAY
VM_CHECKMATCH_TYPE_CASE
VM_CHECKMATCH_TYPE_MASK
VM_CHECKMATCH_TYPE_RESCUE
VM_CHECKMATCH_TYPE_WHEN

Attributes

type[R]

Public Class Methods

new(type) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 426
def initialize(type)
  @type = type
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 442
def ==(other)
  other.is_a?(CheckMatch) && other.type == type
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 458
def call(vm)
  target, pattern = vm.pop(2)

  vm.push(
    if type & VM_CHECKMATCH_ARRAY > 0
      pattern.any? { |item| check?(item, target) }
    else
      check?(pattern, target)
    end
  )
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 438
def deconstruct_keys(_keys)
  { type: type }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 430
def disasm(fmt)
  fmt.instruction("checkmatch", [fmt.object(type)])
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 446
def length
  2
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 450
def pops
  2
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 454
def pushes
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 434
def to_a(_iseq)
  [:checkmatch, type]
end