Class: SyntaxTree::YARV::DefineSMethod
Overview
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
def self.value = "value"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(method_name, method_iseq) ⇒ DefineSMethod
Returns a new instance of DefineSMethod.
1193
1194
1195
1196
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1193
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.
1191
1192
1193
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1191
def method_iseq
@method_iseq
end
|
#method_name ⇒ Object
Returns the value of attribute method_name.
1191
1192
1193
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1191
def method_name
@method_name
end
|
Instance Method Details
#==(other) ⇒ Object
1214
1215
1216
1217
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1214
def ==(other)
other.is_a?(DefineSMethod) && other.method_name == method_name &&
other.method_iseq == method_iseq
end
|
#call(vm) ⇒ Object
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1227
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) ⇒ Object
1210
1211
1212
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1210
def deconstruct_keys(_keys)
{ method_name: method_name, method_iseq: method_iseq }
end
|
#disasm(fmt) ⇒ Object
1198
1199
1200
1201
1202
1203
1204
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1198
def disasm(fmt)
fmt.enqueue(method_iseq)
fmt.instruction(
"definesmethod",
[fmt.object(method_name), method_iseq.name]
)
end
|
#length ⇒ Object
1219
1220
1221
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1219
def length
3
end
|
#pops ⇒ Object
1223
1224
1225
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1223
def pops
1
end
|
#to_a(_iseq) ⇒ Object
1206
1207
1208
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1206
def to_a(_iseq)
[:definesmethod, method_name, method_iseq.to_a]
end
|