Class: SyntaxTree::YARV::SplatArray
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::SplatArray
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
splatarray coerces the array object at the top of the stack into Array by calling to_a. It pushes a duplicate of the array if there is a flag, and the original array if there isn’t one.
### Usage
~~~ruby x = *(5) ~~~
Instance Attribute Summary collapse
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(flag) ⇒ SplatArray
constructor
A new instance of SplatArray.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(flag) ⇒ SplatArray
5842 5843 5844 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5842 def initialize(flag) @flag = flag end |
Instance Attribute Details
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
5840 5841 5842 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5840 def flag @flag end |
Instance Method Details
#==(other) ⇒ Object
5858 5859 5860 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5858 def ==(other) other.is_a?(SplatArray) && other.flag == flag end |
#call(vm) ⇒ Object
5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5878 def call(vm) value = vm.pop vm.push( if Array === value value.instance_of?(Array) ? value.dup : Array[*value] elsif value.nil? value.to_a else if value.respond_to?(:to_a, true) result = value.to_a if result.nil? [value] elsif !result.is_a?(Array) raise TypeError, "expected to_a to return an Array" end else [value] end end ) end |
#canonical ⇒ Object
5874 5875 5876 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5874 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
5854 5855 5856 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5854 def deconstruct_keys(_keys) { flag: flag } end |
#disasm(fmt) ⇒ Object
5846 5847 5848 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5846 def disasm(fmt) fmt.instruction("splatarray", [fmt.object(flag)]) end |
#length ⇒ Object
5862 5863 5864 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5862 def length 2 end |
#pops ⇒ Object
5866 5867 5868 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5866 def pops 1 end |
#pushes ⇒ Object
5870 5871 5872 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5870 def pushes 1 end |
#to_a(_iseq) ⇒ Object
5850 5851 5852 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5850 def to_a(_iseq) [:splatarray, flag] end |