Class: SyntaxTree::YARV::DefineSMethod
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::DefineSMethod
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
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
~~~ruby def self.value = “value” ~~~
Instance Attribute Summary collapse
-
#method_iseq ⇒ Object
readonly
Returns the value of attribute method_iseq.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(method_name, method_iseq) ⇒ DefineSMethod
constructor
A new instance of DefineSMethod.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(method_name, method_iseq) ⇒ DefineSMethod
Returns a new instance of DefineSMethod.
1156 1157 1158 1159 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1156 def initialize(method_name, method_iseq) @method_name = method_name @method_iseq = method_iseq end |
Instance Attribute Details
#method_iseq ⇒ Object (readonly)
Returns the value of attribute method_iseq.
1154 1155 1156 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1154 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
1154 1155 1156 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1154 def method_name @method_name end |
Instance Method Details
#==(other) ⇒ Object
1177 1178 1179 1180 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1177 def ==(other) other.is_a?(DefineSMethod) && other.method_name == method_name && other.method_iseq == method_iseq end |
#call(vm) ⇒ Object
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1198 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 |
#canonical ⇒ Object
1194 1195 1196 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1194 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
1173 1174 1175 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1173 def deconstruct_keys(_keys) { method_name: method_name, method_iseq: method_iseq } end |
#disasm(fmt) ⇒ Object
1161 1162 1163 1164 1165 1166 1167 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1161 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definesmethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
1182 1183 1184 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1182 def length 3 end |
#pops ⇒ Object
1186 1187 1188 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1186 def pops 1 end |
#pushes ⇒ Object
1190 1191 1192 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1190 def pushes 0 end |
#to_a(_iseq) ⇒ Object
1169 1170 1171 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1169 def to_a(_iseq) [:definesmethod, method_name, method_iseq.to_a] end |