Other Pages

Expand All


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


first = "Joe"
last = "Smith"

+ does concatenation

full = first + " " + last

#{} does interpolation

full = "#{first} #{last}"
Back to Learn To Code

If you find something that could be improved, please make a pull request or drop us a note via GitHub Issues (no technical knowledge required).

Source: https://github.com/RailsBridge-CapeTown