Skip to content

Instantly share code, notes, and snippets.

@hauleth
Last active August 29, 2015 14:12
Show Gist options
  • Save hauleth/87d60f8b33684f2cd642 to your computer and use it in GitHub Desktop.
Save hauleth/87d60f8b33684f2cd642 to your computer and use it in GitHub Desktop.
class Wektor
attr_accessor :coords
def initialize(length)
@coords = Array.new(length, 0)
end
def set!(w)
@coords = w.dup
self
end
%i(* /).each do |op|
define_method(op) do |n|
coords.map! { |i| i.send(op, n) }
self
end
end
%i(- +).each do |op|
define_method(op) do |v|
@coords.zip(v).map { |a, b| a.send(op, b) }
self
end
end
def shift_right!
coords.rotate!
coords[0] = 0
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment