# Ruby exception

**URL:** <https://www.ruby-forum.com/t/ruby-exception/82975>\
**Category:** Rails\
**Created:** [November 19, 2005, 1:20pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975 "2005-11-19T13:20:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bogdan.ionescu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bogdan.ionescu](https://www.ruby-forum.com/u/bogdan.ionescu)\
**Post date:** [November 19, 2005, 1:20pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975/1 "2005-11-19T13:20:59Z")

</div>

Is there a logical explanation for this?

1.to\_s+“1” =\> “11”  
1.to\_s+ “1” =\> “11”  
1.to\_s + “1” =\> “11”  
1.to\_s +“1” =\> test.rb:2: undefined method `+@’ for “1”:String  
(NoMethodError)

bogdan

---

<div class="post-metadata">

**Author:** ![bogdan.ionescu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bogdan.ionescu](https://www.ruby-forum.com/u/bogdan.ionescu)\
**Post date:** [November 19, 2005, 3:00pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975/2 "2005-11-19T15:00:35Z")

</div>

Bogdan I. wrote:

> Is there a logical explanation for this?
> 
> 1.to\_s+“1” =\> “11”  
> 1.to\_s+ “1” =\> “11”  
> 1.to\_s + “1” =\> “11”  
> 1.to\_s +“1” =\> test.rb:2: undefined method `+@’ for “1”:String  
> (NoMethodError)

i think the + operator can not be applied to a string. only to a number.  
what are you trying to do?

you can do  
a = +1

but a = +“1” makes no sense to me

---

<div class="post-metadata">

**Author:** ![bogdan.ionescu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bogdan.ionescu](https://www.ruby-forum.com/u/bogdan.ionescu)\
**Post date:** [November 19, 2005, 5:22pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975/3 "2005-11-19T17:22:41Z")

</div>

Nothing really, I ommited typing a space and that resulted into an  
exception  
which eventually I tracked down to that.

---

<div class="post-metadata">

**Author:** ![bogdan.ionescu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bogdan.ionescu](https://www.ruby-forum.com/u/bogdan.ionescu)\
**Post date:** [November 19, 2005, 3:12pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975/4 "2005-11-19T15:12:40Z")

</div>

Bogdan I. wrote:

> Is there a logical explanation for this?
> 
> 1.to\_s+“1” =\> “11”  
> 1.to\_s+ “1” =\> “11”  
> 1.to\_s + “1” =\> “11”  
> 1.to\_s +“1” =\> test.rb:2: undefined method `+@’ for “1”:String  
> (NoMethodError)

When a and b are both strings. Then

a + b means: Call method ‘+’ (binary plus) in string a and give b as  
parameter  
a +b means: Call method ‘+@’ (unary plus) on string b which doesn’t  
exist

+1 is the positive number 1, -1 is the negative number -1, but what  
should +“some string” mean? So it is not defined.

## Jochen

Jochen Topf removed\_email\_address@domain.invalid [http://www.remote.org/jochen/](http://www.remote.org/jochen/)  
+49-721-388298

---

<div class="post-metadata">

**Author:** ![bogdan.ionescu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@bogdan.ionescu](https://www.ruby-forum.com/u/bogdan.ionescu)\
**Post date:** [November 19, 2005, 5:25pm UTC](https://www.ruby-forum.com/t/ruby-exception/82975/5 "2005-11-19T17:25:42Z")

</div>

Thanks, I got it.  
bogdan
