Chapter 5
Mixing It Up

We’ve looked at a few kinds of objects (integers, floats, and strings), and we made variables point to them. Now it’s time for them all to play nicely together.

We’ve seen that if we want a program to print 25, the following does not work, because you can’t add numbers and strings together:

var1 = 2
var2 = ​'5'
puts var1 + var2

Part of the problem is that your computer doesn’t know if you were trying to get 7 (2 + 5) or if you wanted to get 25 ('2' + '5'). But we’ll learn how to do both.

Before we can add these together, we need some way of getting the string version of var1 or of getting the integer version of var2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.43.26