# Error in Loop!

**URL:** <https://www.ruby-forum.com/t/error-in-loop/116114>\
**Category:** Ruby\
**Created:** [October 2, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114 "2007-10-02T15:41:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [October 2, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114/1 "2007-10-02T15:41:08Z")

</div>

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  
#####################################################################################

---

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [October 2, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114/2 "2007-10-02T15:50:40Z")

</div>

0.0 \<\< “hello world”

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

---

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [October 2, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114/3 "2007-10-02T15:52:26Z")

</div>

7stud – wrote:

> 0.0 \<\< “hello world”
> 
> –output:–  
> r6test.rb:1: undefined method `\<\<’ for 0.0:Float (NoMethodError)

Whoops. Not the same error.

---

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [October 2, 2007, 3:54pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114/4 "2007-10-02T15:54:36Z")

</div>

On 10/2/07, John N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![jngo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jngo](https://www.ruby-forum.com/u/jngo)\
**Post date:** [October 2, 2007, 3:54pm UTC](https://www.ruby-forum.com/t/error-in-loop/116114/5 "2007-10-02T15:54:39Z")

</div>

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
