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 ...
Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.