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


why can't you write the syntax as year = "2015"

2 Answers

When you set a variable to a value contained in quotes it becomes a String. Strings will have different methods than numbers will so you won't be able to perform the same operations. For instance:

   >> "100" + "10"
   => "10010"
   >> 100 + 10
   => 110

You can however cast a variable from a string to a number with String#to_i and String#to_f. These attempt to convert a string to an integer and floating point number respectively. These are useful for dealing with user input as it will usually come to you as a string even if you were asking the user for a number.

Thanks Geoff that was really helpful.