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
- #call(vm) ⇒ Object
- #canonical ⇒ 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
1047 1048 1049 1050 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1047 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.
1045 1046 1047 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1045 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
1045 1046 1047 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1045 def method_name @method_name end |
Instance Method Details
#call(vm) ⇒ Object
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1080 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
1076 1077 1078 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1076 def canonical self end |
#disasm(fmt) ⇒ Object
1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1052 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definesmethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
1064 1065 1066 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1064 def length 3 end |
#pops ⇒ Object
1068 1069 1070 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1068 def pops 1 end |
#pushes ⇒ Object
1072 1073 1074 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1072 def pushes 0 end |
#to_a(_iseq) ⇒ Object
1060 1061 1062 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1060 def to_a(_iseq) [:definesmethod, method_name, method_iseq.to_a] end |