Class: RedShift::World::ComponentList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/redshift/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#summandsObject (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

#clearObject



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

#inspectObject



38
39
40
# File 'lib/redshift/world.rb', line 38

def inspect
  to_a.inspect # looks better in irb, but slow
end

#sizeObject



34
35
36
# File 'lib/redshift/world.rb', line 34

def size
  summands.inject(0) { |sum,enum| sum + enum.size }
end