Class: SyntaxTree::YARV::DefineMethod
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(method_name, method_iseq) ⇒ DefineMethod
constructor
A new instance of DefineMethod.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(method_name, method_iseq) ⇒ DefineMethod
975 976 977 978 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 975 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.
973 974 975 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 973 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
973 974 975 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 973 def method_name @method_name end |
Instance Method Details
#call(vm) ⇒ Object
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1008 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 |
#canonical ⇒ Object
1004 1005 1006 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1004 def canonical self end |
#disasm(fmt) ⇒ Object
980 981 982 983 984 985 986 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 980 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definemethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
992 993 994 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 992 def length 3 end |
#pops ⇒ Object
996 997 998 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 996 def pops 0 end |
#pushes ⇒ Object
1000 1001 1002 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1000 def pushes 0 end |
#to_a(_iseq) ⇒ Object
988 989 990 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 988 def to_a(_iseq) [:definemethod, method_name, method_iseq.to_a] end |