Chapter 4. Modules and program organization

This chapter covers
  • Encapsulation of behavior in modules
  • Modular extension of classes
  • The object method-lookup path
  • Handling method-lookup failure
  • Establishing namespaces with modules and nesting

This chapter will introduce you to a Ruby construct that’s closely related to classes: modules. As their name suggests, modules encourage modular design: program design that breaks large components into smaller ones and lets you mix and match object behaviors.

Like classes, modules are bundles of methods and constants. Unlike classes, modules don’t have instances; instead, you specify that you want to add the functionality of a particular module to that of a class or of a specific ...

Get The Well-Grounded Rubyist, Third Edition 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.