Skip to Main Content
Learn to Program, 2nd Edition
book

Learn to Program, 2nd Edition

by Chris Pine
March 2009
Intermediate to advanced content levelIntermediate to advanced
194 pages
4h
English
Pragmatic Bookshelf
Content preview from Learn to Program, 2nd Edition

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…

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn to Program, 3rd Edition

Learn to Program, 3rd Edition

Chris Pine
The Book of Ruby

The Book of Ruby

Huw Collingbourne

Publisher Resources

ISBN: 9781680500172Errata