# Changing the type of a variable

**URL:** <https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169>\
**Category:** Ruby\
**Created:** [May 10, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169 "2006-05-10T21:02:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [May 10, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169/1 "2006-05-10T21:02:31Z")

</div>

Hi,

I’m a ruby newbie, although I’m a programmer with 10yrs experience. I  
was running myself through the tutorial in Agile Web D. With  
Rails, when I ran into a problem. somewhere in the code I mistakenly  
entered

@items = 0

instead of

@items = []

A bit later I tried the following

@items \<\< LineItem.for\_product(product)

but when i try to execute this code I got the following error:

“cannot convert LineItem to Integer”

Looking back through the code, I found the error mentioned above, and  
corrected it. However, Rails still insists that @items is an Integer.  
Can anyone suggest what has gone wrong, or what I can do to fix it?

Alli

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [May 10, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169/2 "2006-05-10T21:04:48Z")

</div>

Oh, btw; I have just registered myself under the pseudo “demallien”…

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [May 10, 2006, 10:08pm UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169/3 "2006-05-10T22:08:32Z")

</div>

On 5/10/06, Allison N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Looking back through the code, I found the error mentioned above, and  
> corrected it. However, Rails still insists that @items is an Integer.  
> Can anyone suggest what has gone wrong, or what I can do to fix it?

If you have restarted webrick, you are probably setting @items to an  
integer somewhere else.

If you have grep, you might want to grep for ‘@items’, in your app or  
controllers directory and look at each assignment. There might be  
another place where you say @items = 0 or @items =  
\<some\_object\_that’s\_an\_integer\>

L

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [May 14, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169/4 "2006-05-14T18:06:53Z")

</div>

On Thu, May 11, 2006 at 04:02:39AM +0900, Allison N. wrote:

> Looking back through the code, I found the error mentioned above, and  
> corrected it. However, Rails still insists that @items is an Integer.  
> Can anyone suggest what has gone wrong, or what I can do to fix it?

```
Make sure you have actually changed all the "@items = 0" occurrences 

```

in  
the code to the correct version, and also make sure that you aren’t  
passing  
around (through a form) any “items” variable to the value “0”.

```
Are those two lines in some controller action? It's not clear 

```

whether  
they are, or if you’re using some external library or something… :-/

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [May 11, 2006, 2:33am UTC](https://www.ruby-forum.com/t/changing-the-type-of-a-variable/60169/5 "2006-05-11T02:33:09Z")

</div>

Allison N. wrote:

> Oh, btw; I have just registered myself under the pseudo “demallien”…

And here I was hoping for “femalien”. Oh, well. 😉

Dan
