class Vector
Public Class Methods
new(x=nil,y=nil)
click to toggle source
# File lib/rtl/vector.rb, line 2 def initialize x=nil,y=nil @array=[x,y] end
Public Instance Methods
+(other)
click to toggle source
# File lib/rtl/vector.rb, line 38 def +(other) res=Vector.new @array.each_with_index do |e,i| res[i]=e + other[i] end return res end
[](idx)
click to toggle source
# File lib/rtl/vector.rb, line 30 def [](idx) @array[idx] end
[]=(idx,val)
click to toggle source
# File lib/rtl/vector.rb, line 34 def []=(idx,val) @array[idx]=val end
first()
click to toggle source
# File lib/rtl/vector.rb, line 22 def first @array.first end
last()
click to toggle source
# File lib/rtl/vector.rb, line 26 def last @array.last end
scale(int)
click to toggle source
# File lib/rtl/vector.rb, line 46 def scale int res=Vector.new @array.each_with_index do |e,i| res[i]=e*int end return res end
squared()
click to toggle source
# File lib/rtl/vector.rb, line 54 def squared res=0 @array.each do |e| res+=e*e end return res end
to_s()
click to toggle source
# File lib/rtl/vector.rb, line 62 def to_s "[#{@array.join(',')}]" end
x()
click to toggle source
# File lib/rtl/vector.rb, line 6 def x return @array[0] end
x=(v)
click to toggle source
# File lib/rtl/vector.rb, line 14 def x=(v) @array[0]=v end
y()
click to toggle source
# File lib/rtl/vector.rb, line 10 def y return @array[1] end
y=(v)
click to toggle source
# File lib/rtl/vector.rb, line 18 def y=(v) @array[1]=v end