Chapter 8. Strings, symbols, and other scalar objects

 

This chapter covers

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

The term scalar comes from mathematics, where it’s defined as an element that has magnitude but not a vector. For example, the temperature outside at any given time is a scalar element, whereas when temperature is measured every day for a month and plotted on a graph, the graph is a vector or non-scalar element.

In programming, scalar has a similar meaning. It refers to objects that represent single values, such as integers and strings, as opposed to collection or container objects that hold multiple values. In our temperature example, we might use a Float to represent the temperature on any given day. When we collect those temperatures together, we store them in an Array. The Float is a scalar object because it represents one and only one data point. The Array is a non-scalar object because it’s a collection of Floats. Non-scalar objects also include hashes, sets, and ranges, all of which we’ll cover in 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

8.1. Working with strings

8.2. Symbols and their uses

8.3. Numerical objects

8.4. Times and dates

Summary

sitemap