Class: RGSS::Batch
Instance Method Summary collapse
- #add(object) ⇒ Object (also: #push, #<<)
- #contains?(object) ⇒ Boolean (also: #include?)
- #each ⇒ Object
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #invalidate ⇒ Object
- #remove(object) ⇒ Object (also: #delete)
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
7 8 9 10 |
# File 'lib/rgss/batch.rb', line 7 def initialize @invalid = false @items = Array.new end |
Instance Method Details
#add(object) ⇒ Object Also known as: push, <<
21 22 23 24 25 26 27 28 29 |
# File 'lib/rgss/batch.rb', line 21 def add(object) unless object.respond_to?(:z) && object.respond_to?(:render) raise(TypeError, "#{object} is not a #{Renderable} instance") end return false if @items.include?(object) @items.push(object) @invalid = true true end |
#contains?(object) ⇒ Boolean Also known as: include?
35 36 37 |
# File 'lib/rgss/batch.rb', line 35 def contains?(object) object.is_a?(Renderable) ? @items.include?(object) : false end |
#each ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rgss/batch.rb', line 12 def each return enum_for(__method__) unless block_given? if @invalid @items.sort! { |a, b| a.z <=> b.z } @invalid = false end @items.each { |item| yield item } end |
#invalidate ⇒ Object
39 40 41 |
# File 'lib/rgss/batch.rb', line 39 def invalidate @invalid = true end |
#remove(object) ⇒ Object Also known as: delete
31 32 33 |
# File 'lib/rgss/batch.rb', line 31 def remove(object) @items.delete(object) end |