×

ruby · level 1 · unit 3 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Text and numbers look alike, but Ruby treats them differently.

5 is a number. "5" is a string that happens to hold the digit 5. Whole numbers like 5 are called integers. Ruby can do maths with integers, but not with strings.

With strings, + joins: "5" + "3" makes "53". With integers, + adds: 5 + 3 makes 8. Mix them, like "5" + 3, and Ruby stops with a .

Not sure which kind a value is? Every value has a , which says what kind of thing it is. Add .class to find out: 5.class is and "5".class is String.

puts "5" + "3"
puts 5 + 3
puts 5.class
puts "5".class

Quotes are the clue: with quotes it is text, without quotes it is a number.