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.
1013 1014 1015 1016 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1013 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.
1011 1012 1013 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1011 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
1011 1012 1013 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1011 def method_name @method_name end |
Instance Method Details
#==(other) ⇒ Object
1034 1035 1036 1037 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1034 def ==(other) other.is_a?(DefineMethod) && other.method_name == method_name && other.method_iseq == method_iseq end |
#call(vm) ⇒ Object
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1043 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
1030 1031 1032 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1030 def deconstruct_keys(_keys) { method_name: method_name, method_iseq: method_iseq } end |
#disasm(fmt) ⇒ Object
1018 1019 1020 1021 1022 1023 1024 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1018 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definemethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
1039 1040 1041 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1039 def length 3 end |
#to_a(_iseq) ⇒ Object
1026 1027 1028 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1026 def to_a(_iseq) [:definemethod, method_name, method_iseq.to_a] end |