12 vs. ’12’

Before we get any further, we should make sure we understand the difference between numbers and digits. 12 is a number, but '12' is a string of two digits.

Let’s play around with this for a while:

puts 12 + 12
puts ​'12'​ + ​'12'
puts ​'12 + 12'
24
1212
12 + 12

How about this?

puts 2 * 5
puts ​'2'​ * 5
puts ​'2 * 5'
10
22222
2 * 5

These examples are pretty clear. However, if you’re not too careful with how you mix your strings and your numbers, you might run into…

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

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