Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m really new in ruby (maybe few hours that I have started ruby) When I run th

ID: 3552045 • Letter: I

Question

 
I'm really new in ruby (maybe few hours that I have started ruby)


When I run the program I get into infinite loop, I don't understand why.


Thank you.

 # MyVector Class class  MyVector   def initialize (a)     if !(a.instance_of? Array)       raise "ARGUMENT OF INITIALIZER MUST BE AN ARRAY"     else       @array = a     end   end    def array     @array   end    def to_s     @array.to_s   end    def length     @array.length   end    def [](i)     @array[i]   end    def each2(a)     raise Error, "INTEGER IS NOT LIKE VECTOR" if a.kind_of?(Integer)     Vector.Raise Error if length != a.length     return to_enum(:each2, a) unless block_given?     length.times do |i|       yield @array[i], a[i]     end     self   end    def * (a)     Vector.Raise Error if length != a.length     p = 0     each2(a) {|a1, a2|p += a1 * a2}     p   end end  # MyMatrix Class class MyMatrix   def initialize a     @array=Array.new(a.length)     i=0     while(i<a.length)       @array[i]=MyVector.new(a[i])     end   end    def to_s     @array.to_s   end    def transpose     size=vectors[0].length     arr= Array.new(size)     i=0     while i<size       a=Array.new(vector.length)       j=0       while j<a.length         a[j]=vectors[j].arr[i]         j+=1       end       arr[i]=a       i+=1     end     arr[i]=a     i+=1   end    def *m     if !(m instance_of? MyMatrix)       raise Error       a=Array.new(@array.length)       i=0       while (i<@array.length)         a[i]=@array[i]*m         i=i+1       end     end   end end 

Explanation / Answer

Desired Output: