Module: Vissen::Output::Buffer
- Extended by:
- Forwardable
- Included in:
- PixelBuffer, VixelBuffer
- Defined in:
- lib/vissen/output/buffer.rb
Overview
Buffer
Instance Attribute Summary collapse
-
#context ⇒ Context
readonly
The context of the buffer.
-
#elements ⇒ Object
readonly
The elements at the buffer points.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Context specific element accessor.
-
#each_with_position ⇒ see Context#each_position
Iterates over each element in the buffer and yields the element along with its x and y coordinates.
-
#freeze ⇒ self
Prevents the context and element array from being changed.
-
#initialize(context, elements_klass = nil, &block) ⇒ Object
The grid is setup with a grid context as well as a class to places instances of in every grid point.
-
#share_context?(other) ⇒ true, false
(also: #===)
Two buffers are considered equal if they share the same context.
Instance Attribute Details
#context ⇒ Context (readonly)
Returns the context of the buffer.
14 15 16 |
# File 'lib/vissen/output/buffer.rb', line 14 def context @context end |
#elements ⇒ Object (readonly)
Returns the elements at the buffer points.
17 18 19 |
# File 'lib/vissen/output/buffer.rb', line 17 def elements @elements end |
Instance Method Details
#[](*args) ⇒ Object
Context specific element accessor. Depends on ‘Context#index_from` to transform `args` into an index.
56 57 58 |
# File 'lib/vissen/output/buffer.rb', line 56 def [](*args) @elements[@context.index_from(*args)] end |
#each_with_position ⇒ see Context#each_position
Iterates over each element in the buffer and yields the element along with its x and y coordinates.
64 65 66 67 |
# File 'lib/vissen/output/buffer.rb', line 64 def each_with_position return to_enum(__callee__) unless block_given? @context.each_position { |i, x, y| yield @elements[i], x, y } end |
#freeze ⇒ self
Prevents the context and element array from being changed.
46 47 48 49 |
# File 'lib/vissen/output/buffer.rb', line 46 def freeze @elements.freeze super end |
#initialize(context, elements_klass = nil, &block) ⇒ Object
The grid is setup with a grid context as well as a class to places instances of in every grid point.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vissen/output/buffer.rb', line 32 def initialize(context, elements_klass = nil, &block) @context = context @elements = if block_given? raise ArgumentError if elements_klass context.alloc_points(&block).freeze else context.alloc_points(elements_klass).freeze end end |
#share_context?(other) ⇒ true, false Also known as: ===
Two buffers are considered equal if they share the same context.
73 74 75 76 77 |
# File 'lib/vissen/output/buffer.rb', line 73 def share_context?(other) @context == other.context rescue NoMethodError false end |