module Vissen::Output::Buffer

Buffer

Attributes

context[R]

@return [Context] the context of the buffer.

elements[R]

@return [Object] the elements at the buffer points.

Public Class Methods

new(context, elements_klass = nil, &block) click to toggle source

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

===(other)
Alias for: share_context?
[](*args) click to toggle source

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
each_with_position() { |elements, x, y| ... } click to toggle source

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
freeze() click to toggle source

Prevents the context and element array from being changed.

@return [self]

Calls superclass method
# File lib/vissen/output/buffer.rb, line 46
def freeze
  @elements.freeze
  super
end
share_context?(other) click to toggle source

Two buffers are considered equal if they share the same context.

@param other [#context, Object] @return [true, false] true if the other object share the same context.

# File lib/vissen/output/buffer.rb, line 73
def share_context?(other)
  @context == other.context
rescue NoMethodError
  false
end
Also aliased as: ===