Class: SyntaxTree::YARV::DefineMethod
Overview
Summary
definemethod defines a method on the 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.
Usage
def value = "value"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #pushes, #side_effects?
Constructor Details
#initialize(method_name, method_iseq) ⇒ DefineMethod
Returns a new instance of DefineMethod.
1071
1072
1073
1074
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1071
def initialize(method_name, method_iseq)
@method_name = method_name
@method_iseq = method_iseq
end
|
Instance Attribute Details
#method_iseq ⇒ Object
Returns the value of attribute method_iseq.
1069
1070
1071
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1069
def method_iseq
@method_iseq
end
|
#method_name ⇒ Object
Returns the value of attribute method_name.
1069
1070
1071
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1069
def method_name
@method_name
end
|
Instance Method Details
#==(other) ⇒ Object
1092
1093
1094
1095
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1092
def ==(other)
other.is_a?(DefineMethod) && other.method_name == method_name &&
other.method_iseq == method_iseq
end
|
#call(vm) ⇒ Object
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1101
def call(vm)
name = method_name
nesting = vm.frame.nesting
iseq = method_iseq
vm
.frame
._self
.__send__(:define_method, name) do |*args, **kwargs, &block|
vm.run_method_frame(
name,
nesting,
iseq,
self,
*args,
**kwargs,
&block
)
end
end
|
#deconstruct_keys(_keys) ⇒ Object
1088
1089
1090
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1088
def deconstruct_keys(_keys)
{ method_name: method_name, method_iseq: method_iseq }
end
|
#disasm(fmt) ⇒ Object
1076
1077
1078
1079
1080
1081
1082
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1076
def disasm(fmt)
fmt.enqueue(method_iseq)
fmt.instruction(
"definemethod",
[fmt.object(method_name), method_iseq.name]
)
end
|
#length ⇒ Object
1097
1098
1099
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1097
def length
3
end
|
#to_a(_iseq) ⇒ Object
1084
1085
1086
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1084
def to_a(_iseq)
[:definemethod, method_name, method_iseq.to_a]
end
|