class SyntaxTree::YARV::GetConstant
### Summary
‘getconstant` performs a constant lookup and pushes the value of the constant onto the stack. It pops both the class it should look in and whether or not it should look globally as well.
### Usage
~~~ruby Constant ~~~
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1707 def initialize(name) @name = name end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1723 def ==(other) other.is_a?(GetConstant) && other.name == name end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1739 def call(vm) const_base, allow_nil = vm.pop(2) if const_base if const_base.const_defined?(name) vm.push(const_base.const_get(name)) return end elsif const_base.nil? && allow_nil vm.frame.nesting.reverse_each do |clazz| if clazz.const_defined?(name) vm.push(clazz.const_get(name)) return end end end raise NameError, "uninitialized constant #{name}" end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1719 def deconstruct_keys(_keys) { name: name } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1711 def disasm(fmt) fmt.instruction("getconstant", [fmt.object(name)]) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 1715 def to_a(_iseq) [:getconstant, name] end