Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics (Retired) Ruby Numbers Different Kinds of Numbers

Just to stir the pot a bit: Why wouldn't Ruby concatenate a FixedNum and a String vs. Erroring Out?

I know that we cannot add strings and numbers, but the example code was:

a + name 

...which produces an error. So I wonder though how/why Ruby knows that this is an addition problem vs. concatenation. We haven't discussed the syntax of concatenation in Ruby yet, but in other languages + is the concatenate. So that's what got me wondering about this. Thanks for any help you can offer to clarify this.

2 Answers

So Nekilof, I have to say you did a great job! All you need is to define the name variable first. Also, you need to put double quotes around the string. Try something like this:

name = "Nekilof"
"a" + name
rowend rowend
rowend rowend
2,926 Points

I think ruby compares the values of the operators and check if they are compatible and then make the math action or the concatenation action or give you an error.