Module: Carbuncle::Vectorizable::ClassMethods

Included in:
Color, Point, Rect, Carbuncle::Vector3, Carbuncle::Vector4
Defined in:
gems/carbuncle-math/mrblib/000-vectorizable.rb

Instance Method Summary collapse

Instance Method Details

#vectorize_properties(properties) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'gems/carbuncle-math/mrblib/000-vectorizable.rb', line 12

def vectorize_properties(properties)
  (2..properties.size).each do |i|
    properties.permutation(i) do |fields|
      define_method(fields.join) do
        Vectorizable::CLASS[i].new(*fields.map { |field| send(field) })
      end
    
      define_method("#{fields.join}=") do |other|
        i.times do |index|
          send(:"#{fields[index]}=", other[index])
        end
      end
    end
  end
end