String Messages

A string understands lots of messages. Here are a few:

"Fig Newton".swapcase

Try all of these out in irb!

String Operators

A string knows DOT, but also understands several other operators:

"blue" + "berry"
"yum" * 10

+ * and [] are pronounced PLUS, TIMES, and SUB

Try these out in irb!

Combining Messages and Operators

You can combine messages and operators at will.

"grape".reverse * 10 + "!!!"

Definitely try these out in irb! It's pretty fun.

LAB: Playing With Strings

  • What is the reverse of "stressed"?
  • How many characters long is your name?
  • What does your name look like, repeated 1000 times?
  • What is the tenth character of "Matz is nice"? (Trick question!)


first = "Joe"
last = "Smith"

+ does concatenation

full = first + " " + last

#{} does interpolation

full = "#{first} #{last}"