Class: Musicality::CompoundSequence
- Inherits:
-
Object
- Object
- Musicality::CompoundSequence
- Defined in:
- lib/musicality/composition/util/compound_sequence.rb
Instance Method Summary collapse
- #at(offset) ⇒ Object
-
#initialize(combine_method, sequences) ⇒ CompoundSequence
constructor
A new instance of CompoundSequence.
- #over(range) ⇒ Object
- #take(n) ⇒ Object
- #take_back(n) ⇒ Object
Constructor Details
#initialize(combine_method, sequences) ⇒ CompoundSequence
Returns a new instance of CompoundSequence.
4 5 6 7 |
# File 'lib/musicality/composition/util/compound_sequence.rb', line 4 def initialize combine_method, sequences @seqs = sequences @comb_meth = combine_method end |
Instance Method Details
#at(offset) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/musicality/composition/util/compound_sequence.rb', line 9 def at offset if offset.is_a? Enumerable return enum_for(:at,offset) unless block_given? enums = @seqs.map {|s| s.at(offset) } offset.size.times { yield combine(enums.map {|e| e.next }) } else vals = @seqs.map {|s| s.at(offset) } return combine(vals) end end |
#over(range) ⇒ Object
26 27 28 29 30 |
# File 'lib/musicality/composition/util/compound_sequence.rb', line 26 def over range return enum_for(:over,range) unless block_given? enums = @seqs.map {|s| s.over(range) } range.size.times { yield combine(enums.map {|e| e.next }) } end |
#take(n) ⇒ Object
20 21 22 23 24 |
# File 'lib/musicality/composition/util/compound_sequence.rb', line 20 def take n return enum_for(:take,n) unless block_given? enums = @seqs.map {|s| s.take(n) } n.times { yield combine(enums.map {|e| e.next }) } end |
#take_back(n) ⇒ Object
32 33 34 35 36 |
# File 'lib/musicality/composition/util/compound_sequence.rb', line 32 def take_back n return enum_for(:take_back,n) unless block_given? enums = @seqs.map {|s| s.take_back(n) } n.times { yield combine(enums.map {|e| e.next }) } end |