Error in Loop!

Hi Everyone!
I keep getting the following error message for this line of the below
code:

mat1[r,c] << this_record.chomp(",").strip()

I have been racking my brain but can’t see a sollution - have used this
line before so pretty baffled!!
Anyone got any ideas - would be very appreciated!
The error message is:

Error: private method `<<' called for 0.0:Float

HERE IS THE FULL CODE

mat1 = OtMatrix.new(19,649)

r = 0
c = 1

while ( !file.eof )
line = file.gets
r = r+1
line.each(’,’) { |this_record|
mat1[r,c] << this_record.chomp(",").strip()
c = c+1
if c == 19 then
c == 1
end
}

end

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal
#####################################################################################

0.0 << “hello world”

–output:–
r6test.rb:1: undefined method `<<’ for 0.0:Float (NoMethodError)

7stud – wrote:

0.0 << “hello world”

–output:–
r6test.rb:1: undefined method `<<’ for 0.0:Float (NoMethodError)

Whoops. Not the same error.

On 10/2/07, John N. [email protected] wrote:

Hi Everyone!
I keep getting the following error message for this line of the below code:

mat1[r,c] << this_record.chomp(",").strip()
You try to append the RHS to a float, which is what
mat1[r,c] evaluates to, that does not work of course.

It is difficult to fix the error because I do not know what you want to
achieve
depending on the API of OtMatrix maybe the following would make sense

mat1[r] << RHS # adding an element to a row, however now you might
have an irregular matrix
mat1 << RHS # adding a new line at the end of the Matrix, is this what
you want?

HTH
Robert

John N. wrote:

mat1[r,c] << this_record.chomp(",").strip()

Is there an << operator defined for that class? Are you sure it
shouldn’t be:

mat1[r,c] = this_record.chomp(",").strip(0

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs