Class: RVM::Interpreter::Sequence
- Defined in:
- lib/rvm/interpreter.rb
Overview
A sequence is a list of commands that are executed one after another. The type of the squence is equal to the last element of the sequence.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#pos ⇒ Object
Returns the value of attribute pos.
Instance Method Summary collapse
-
#+(v) ⇒ Object
When adding something to the Sequence a new Sequence will be created with the result of the joined arrays.
- #<<(v) ⇒ Object
-
#data_type ⇒ Object
The data type of the list is :any as it is unknown where the the sequence exits.
-
#execute(env) ⇒ Object
When exeuted a sequence starts to execute every element in it starting with the first element in the array.
-
#initialize(src = [], pos = nil) ⇒ Sequence
constructor
The Sequence is initialized wiht 1 to 2 parameters.
-
#optimize ⇒ Object
Optimization for sequences.
- #pretty_print(q) ⇒ Object
- #unshift(v) ⇒ Object
Constructor Details
#initialize(src = [], pos = nil) ⇒ Sequence
The Sequence is initialized wiht 1 to 2 parameters.
- src
-
The source is an array that holds the inital list of commands that are supposed to be executed.
- pos
-
The position within the source code of the definition - for deugging purpose.
712 713 714 715 |
# File 'lib/rvm/interpreter.rb', line 712 def initialize src=[], pos = nil @data = src @pos = pos end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
703 704 705 |
# File 'lib/rvm/interpreter.rb', line 703 def data @data end |
#pos ⇒ Object
Returns the value of attribute pos.
702 703 704 |
# File 'lib/rvm/interpreter.rb', line 702 def pos @pos end |
Instance Method Details
#+(v) ⇒ Object
When adding something to the Sequence a new Sequence will be created with the result of the joined arrays.
747 748 749 750 |
# File 'lib/rvm/interpreter.rb', line 747 def + v v = v.data if v.is_a? RVM::Interpreter::Sequence Sequence.new(@data + v) end |
#<<(v) ⇒ Object
752 753 754 755 |
# File 'lib/rvm/interpreter.rb', line 752 def << v @data << v self end |
#data_type ⇒ Object
The data type of the list is :any as it is unknown where the the sequence exits.
784 785 786 |
# File 'lib/rvm/interpreter.rb', line 784 def data_type :any end |
#execute(env) ⇒ Object
When exeuted a sequence starts to execute every element in it starting with the first element in the array.
The result is the last element of the array executed.
737 738 739 740 741 742 743 |
# File 'lib/rvm/interpreter.rb', line 737 def execute env RVM::debug "Executing Sequence... #{inspect}" if $DEBUG for item in @data r = item.execute env end r end |
#optimize ⇒ Object
Optimization for sequences
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'lib/rvm/interpreter.rb', line 763 def optimize if @data.size == 1 return @data.first.optimize else newdata = [] @data.each do |d| d = d.optimize if d.is_a? RVM::Interpreter::Sequence newdata.concat(d.data) else newdata << d end end @data = newdata end super end |
#pretty_print(q) ⇒ Object
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'lib/rvm/interpreter.rb', line 717 def pretty_print(q) first = true q.group 1, "{", "}" do @data.each do |c| if first first = false else q.text ";" end q.breakable q.pp c end q.breakable end end |
#unshift(v) ⇒ Object
757 758 759 760 |
# File 'lib/rvm/interpreter.rb', line 757 def unshift v @data.unshift v self end |