Text
Text is represented in Ruby by objects of the String
class. Strings are mutable objects, and the String
class defines a powerful set of
operators and methods for extracting substrings, inserting and deleting
text, searching, replacing, and so on. Ruby provides a number of ways to
express string literals in your programs, and some of them support a
powerful string interpolation syntax by which the values of arbitrary
Ruby expressions can be substituted into string literals. The sections
that follow explain string and character literals and string operators.
The full string API is covered in Strings.
Textual patterns are represented in Ruby as Regexp
objects,
and Ruby defines a syntax for including regular expressions literally in
your programs. The code /[a-z]\d+/
,
for example, represents a single lowercase letter followed by one or
more digits. Regular expressions are a commonly used feature of Ruby,
but regexps are not a fundamental datatype in the way that numbers,
strings, and arrays are. See Regular Expressions for
documentation of regular expression syntax and the Regexp
API.
String Literals
Ruby provides quite a few ways to embed strings literally ...
Get The Ruby Programming Language 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.