class SyntaxTree::YARV::DefineSMethod

### Summary

‘definesmethod` defines a method on the singleton class of the current value of `self`. It accepts two arguments. The first is the name of the method being defined. The second is the instruction sequence representing the body of the method. It pops the object off the stack that the method should be defined on.

### Usage

~~~ruby def self.value = “value” ~~~

Attributes

method_iseq[R]
method_name[R]

Public Class Methods

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

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1161
def ==(other)
  other.is_a?(DefineSMethod) && other.method_name == method_name &&
    other.method_iseq == method_iseq
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1174
def call(vm)
  name = method_name
  nesting = vm.frame.nesting
  iseq = method_iseq

  vm
    .frame
    ._self
    .__send__(:define_singleton_method, name) do |*args, **kwargs, &block|
      vm.run_method_frame(
        name,
        nesting,
        iseq,
        self,
        *args,
        **kwargs,
        &block
      )
    end
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1157
def deconstruct_keys(_keys)
  { method_name: method_name, method_iseq: method_iseq }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1145
def disasm(fmt)
  fmt.enqueue(method_iseq)
  fmt.instruction(
    "definesmethod",
    [fmt.object(method_name), method_iseq.name]
  )
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1166
def length
  3
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1170
def pops
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1153
def to_a(_iseq)
  [:definesmethod, method_name, method_iseq.to_a]
end