class SyntaxTree::YARV::SetClassVariable
### Summary
‘setclassvariable` looks for a class variable in the current class and sets its value to the value it pops off the top of the stack. It uses an inline cache to reduce the need to lookup the class variable in the class hierarchy every time.
### Usage
~~~ruby @@class_variable = 1 ~~~
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5108 def initialize(name, cache) @name = name @cache = cache end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5128 def ==(other) other.is_a?(SetClassVariable) && other.name == name && other.cache == cache end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5141 def call(vm) clazz = vm.frame._self clazz = clazz.class unless clazz.is_a?(Class) clazz.class_variable_set(name, vm.pop) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5124 def deconstruct_keys(_keys) { name: name, cache: cache } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5113 def disasm(fmt) fmt.instruction( "setclassvariable", [fmt.object(name), fmt.inline_storage(cache)] ) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5120 def to_a(_iseq) [:setclassvariable, name, cache] end