Class: RGSS::Batch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rgss/batch.rb

Instance Method Summary collapse

Constructor Details

#initializeBatch

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?

Returns:

  • (Boolean)


35
36
37
# File 'lib/rgss/batch.rb', line 35

def contains?(object)
  object.is_a?(Renderable) ? @items.include?(object) : false
end

#eachObject



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

#invalidateObject



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