O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Strings

A string holds characters and nothing else. It is Ruby's only single-purpose container.

As the name suggests, a string has a beginning and an end; it is an ordered container. It might just as accurately have been called a “chain.” If the organizing principle were a “bag” instead, then the characters could be scrambled; we would be able to distinguish list from still, but not fare from fear.

Two strings are considered equal only if they have the exact same characters in the exact same sequence.

"fare" == "fear"      #–> false
"Night" == "night"    #–> false
"nine " == " nine "   #–> false
"rabbit" == "rabbit"  #–> true

Specifying Substrings by Position

Each position in a string has a numerical index. In good computer science tradition, Ruby's indices ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required