Class: VectorSpace::SimpleIndexedVector

Inherits:
SimpleVector show all
Includes:
Family
Defined in:
lib/vector_space/simple_indexed_vector.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Family

included

Methods inherited from SimpleVector

#[], description_separator, #each, has_description_prefix, has_description_separator, has_description_suffix, has_dimension, has_zero_description, #to_s

Methods included from VectorSpace

included

Constructor Details

#initialize(attributes = {}) ⇒ SimpleIndexedVector

Returns a new instance of SimpleIndexedVector.



5
6
7
8
9
10
11
# File 'lib/vector_space/simple_indexed_vector.rb', line 5

def initialize(attributes = {})
  if index_value = attributes[index] || reflect_on_component(index).default
    super attributes.merge(index => index_value)
  else
    raise ArgumentError, "must provide value for #{index} index or configure a default"
  end
end

Class Method Details

.indexed_by(index, attributes = {}) ⇒ Object



23
24
25
26
27
# File 'lib/vector_space/simple_indexed_vector.rb', line 23

def indexed_by(index, attributes = {})
  define_method (reflection = super(index, attributes)).getter do
    reflection.value(@attributes[index])
  end
end