class SyntaxTree::YARV::SplatArray

### Summary

‘splatarray` coerces the array object at the top of the stack into Array by calling `to_a`. It pushes a duplicate of the array if there is a flag, and the original array if there isn’t one.

### Usage

~~~ruby x = *(5) ~~~

Attributes

flag[R]

Public Class Methods

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

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5452
def ==(other)
  other.is_a?(SplatArray) && other.flag == flag
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5468
def call(vm)
  value = vm.pop

  vm.push(
    if Array === value
      value.instance_of?(Array) ? value.dup : Array[*value]
    elsif value.nil?
      value.to_a
    else
      if value.respond_to?(:to_a, true)
        result = value.to_a

        if result.nil?
          [value]
        elsif !result.is_a?(Array)
          raise TypeError, "expected to_a to return an Array"
        end
      else
        [value]
      end
    end
  )
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5448
def deconstruct_keys(_keys)
  { flag: flag }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5440
def disasm(fmt)
  fmt.instruction("splatarray", [fmt.object(flag)])
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5456
def length
  2
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5460
def pops
  1
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5464
def pushes
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5444
def to_a(_iseq)
  [:splatarray, flag]
end