module Vissen::Output::Buffer
Attributes
@return [Context] the context of the buffer.
@return [Object] the elements at the buffer points.
Public Class Methods
The grid is setup with a grid context as well as a class to places instances of in every grid point.
@raise [ArgumentError] if both an element class and a block are given.
@param context [Context] the context in which the buffer exists. @param elements_klass [Class] the class to use when allocating
elements.
@param block [Proc] the block to use instead of `elements_klass` when
allocating element objects.
# 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
Public Instance Methods
Context
specific element accessor. Depends on `Context#index_from` to transform `args` into an index.
@param args (see Context#index_from
). @return [Object] the element at the given index.
# File lib/vissen/output/buffer.rb, line 56 def [](*args) @elements[@context.index_from(*args)] end
Iterates over each element in the buffer and yields the element along with its x and y coordinates.
@return (see Context#each_position
).
# 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
Prevents the context and element array from being changed.
@return [self]
# File lib/vissen/output/buffer.rb, line 46 def freeze @elements.freeze super end