class SyntaxTree::YARV::Once
### Summary
‘once` is an instruction that wraps an instruction sequence and ensures that is it only ever executed once for the lifetime of the program. It uses a cache to ensure that it is only executed once. It pushes the result of running the instruction sequence onto the stack.
### Usage
~~~ruby END { puts “END” } ~~~
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2671 def initialize(iseq, cache) @iseq = iseq @cache = cache end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2689 def ==(other) other.is_a?(Once) && other.iseq == iseq && other.cache == cache end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2701 def call(vm) return if @executed vm.push(vm.run_block_frame(iseq, vm.frame)) @executed = true end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2685 def deconstruct_keys(_keys) { iseq: iseq, cache: cache } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2676 def disasm(fmt) fmt.enqueue(iseq) fmt.instruction("once", [iseq.name, fmt.inline_storage(cache)]) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 2681 def to_a(_iseq) [:once, iseq.to_a, cache] end