Method: AppMath::Vec#initialize
- Defined in:
- lib/linalg.rb
#initialize(*arg) ⇒ Vec
These are the 3 mehods to generate a vector via ‘new’
a = Vec.new(anArray)
b = Vec.new(aVec)
c = Vec.new(aPositiveInteger, aRealOrComplex)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/linalg.rb', line 59 def initialize(*arg) case arg.size when 1 a0 = arg[0] if a0.is_a?(Array) @x = Array.new(a0) # @x = a0 # seems to work but can't be safe elsif a0.is_a?(Vec) @x = Array.new(a0.x) else fail "object can't be used to build a vector" end when 2 n = arg[0] fail "first argument has to be an integer" unless n.integer? fail "first argument must be non-negative" unless n >= 0 @x = Array.new(n,arg[1]) end end |