Chapter 9. The Ruby Platform

image with no caption

Ruby’s core library defines a rich and powerful API that serves as a platform on which to create your programs. It is well worth your time to study and master this API, particularly the key classes such as String, Array, Hash, Enumerable, and IO. If you aren’t familiar with the methods defined by these classes, you may end up spending time reinventing functionality that is already provided for you.

This chapter documents those methods. It is not a comprehensive API reference, but attempts to illustrate, with short code snippets, the use of the important methods of all the important core classes and modules, and a few of the most commonly used classes from the standard library. The aim is to familiarize you with the broad range of existing methods, so that when you need one of them, you will remember that it exists and will be able to find its documentation with ri.

This is a long chapter, broken down into sections that cover the following:

  • Strings and text processing

  • Regular expressions

  • Numbers and math

  • Dates and times

  • The Enumerable module and the Array, Hash and Set collections

  • Input/output and files

  • Networking

  • Threads and concurrency

You’ll find that the code early in the chapter takes the form of one-line snippets demonstrating individual methods. Toward the end, however, when documenting networking and threads, the examples become longer and demonstrate how ...

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.