Chapter 8. Strings, symbols, and other scalar objects

 

In this chapter

  • String object creation and manipulation
  • Methods for transforming strings
  • Symbol semantics
  • String/symbol comparison
  • Integers and floats
  • Time and date objects

The term scalar means one-dimensional. Here, it refers to objects that represent single values, as opposed to collection or container objects that hold multiple values. There are some shades of gray: strings, for example, can be viewed as collections of characters in addition to being single units of text. Scalar is to some extent in the eye of the beholder. Still, as a good first approximation, you can look at the classes discussed in this chapter as classes of one-dimensional, bite-sized objects, in contrast to the collection objects that will be the focus of the next chapter.

The built-in objects we’ll look at in this chapter include the following:

  • Strings, which are Ruby’s standard way of handling textual material of any length
  • Symbols, which are (among other things) another way of representing text in Ruby
  • Integers
  • Floating-point numbers
  • Time, Date, and DateTime objects

All of these otherwise rather disparate objects have in common that they’re scalar—that is, they’re one-dimensional, non-container objects with no further objects lurking inside them. This isn’t to say they’re not complex and rich in their semantics, which, as you’ll see, they are.

8.1. Working with strings

8.2. Symbols and their uses

8.3. Numerical objects

8.4. Times and dates

8.5. Summary