Class: SyntaxTree::YARV::DefineMethod
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::DefineMethod
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
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
~~~ruby def 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
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(method_name, method_iseq) ⇒ DefineMethod
constructor
A new instance of DefineMethod.
- #length ⇒ Object
- #to_a(_iseq) ⇒ Object
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.
1124 1125 1126 1127 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1124 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.
1122 1123 1124 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1122 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
1122 1123 1124 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1122 def method_name @method_name end |
Instance Method Details
#==(other) ⇒ Object
1145 1146 1147 1148 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1145 def ==(other) other.is_a?(DefineMethod) && other.method_name == method_name && other.method_iseq == method_iseq end |
#call(vm) ⇒ Object
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1154 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
1141 1142 1143 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1141 def deconstruct_keys(_keys) { method_name: method_name, method_iseq: method_iseq } end |
#disasm(fmt) ⇒ Object
1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1129 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definemethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
1150 1151 1152 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1150 def length 3 end |
#to_a(_iseq) ⇒ Object
1137 1138 1139 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1137 def to_a(_iseq) [:definemethod, method_name, method_iseq.to_a] end |