class SyntaxTree::YARV::AnyToString

### Summary

‘anytostring` ensures that the value on top of the stack is a string.

It pops two values off the stack. If the first value is a string it pushes it back on the stack. If the first value is not a string, it uses Ruby’s built in string coercion to coerce the second value to a string and then pushes that back on the stack.

This is used in conjunction with ‘objtostring` as a fallback for when an object’s ‘to_s` method does not return a string.

### Usage

~~~ruby “#{5}” ~~~

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 136
def ==(other)
  other.is_a?(AnyToString)
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 148
def call(vm)
  original, value = vm.pop(2)

  if value.is_a?(String)
    vm.push(value)
  else
    vm.push("#<#{original.class.name}:0000>")
  end
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 132
def deconstruct_keys(_keys)
  {}
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 124
def disasm(fmt)
  fmt.instruction("anytostring")
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 140
def pops
  2
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 144
def pushes
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 128
def to_a(_iseq)
  [:anytostring]
end