Chapter 7. Built-in essentials

 

This chapter covers

  • Literal object constructors
  • Syntactic sugar
  • “Dangerous” and/or destructive methods
  • The to_* family of conversion methods
  • Boolean states and objects, and nil
  • Object-comparison techniques
  • Runtime inspection of objects’ capabilities

The term “built-in” is commonly used among Rubyists to describe utility classes found in the core library. Some of the most popular core library classes and standard library classes are listed in table 7.1.

Table 7.1. Popular core and standard library classes (view table figure)

Popular built-in classes

Popular standard library classes

Array Binding Dir Exception File Float Hash IO Integer Kernel Math Mutex Proc Process Random Range Rational String Struct Symbol Thread Time Base64 Benchmark BigDecimal CSV Date Digest ERB FileUtils JSON Logger net/* methods open* methods Pathname PrettyPrint Prime Psych Rake Rdoc Scanf Set Shell Singleton Socket StringIO Tempfile Time URI WEBrick YAML

Array, Hash, String, and Float are all built-in classes because they’re useful and prevalent go-tos available without so much as a require statement. By contrast, Date is not a built-in class because one must require 'date' before using it.

7.1. Ruby’s literal constructors

7.2. Recurrent syntactic sugar

7.3. Bang (!) methods and “danger”

7.4. Built-in and custom to_* (conversion) methods

7.5. Boolean states, Boolean objects, and nil

7.6. Comparing two objects

7.7. Inspecting object capabilities

Summary

sitemap