Class: RedShift::World::ComponentList
- Includes:
- Enumerable
- Defined in:
- lib/redshift/world.rb
Instance Attribute Summary collapse
-
#summands ⇒ Object
readonly
Returns the value of attribute summands.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(*summands) ⇒ ComponentList
constructor
A new instance of ComponentList.
- #inspect ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(*summands) ⇒ ComponentList
Returns a new instance of ComponentList.
25 26 27 |
# File 'lib/redshift/world.rb', line 25 def initialize(*summands) @summands = summands end |
Instance Attribute Details
#summands ⇒ Object (readonly)
Returns the value of attribute summands.
23 24 25 |
# File 'lib/redshift/world.rb', line 23 def summands @summands end |
Instance Method Details
#[](idx) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/redshift/world.rb', line 42 def [](idx) n = nil summands.each do |enum| n = enum.size return enum[idx] if idx < n idx - n end nil end |
#clear ⇒ Object
52 53 54 |
# File 'lib/redshift/world.rb', line 52 def clear summands.each {|list| list.clear} end |
#each(&block) ⇒ Object
29 30 31 32 |
# File 'lib/redshift/world.rb', line 29 def each(&block) summands.each { |enum| enum.each(&block) } self end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/redshift/world.rb', line 38 def inspect to_a.inspect # looks better in irb, but slow end |
#size ⇒ Object
34 35 36 |
# File 'lib/redshift/world.rb', line 34 def size summands.inject(0) { |sum,enum| sum + enum.size } end |