O'Reilly logo

The Well-Grounded Rubyist by David A. Black

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Modules and program organization

 

In this chapter

  • 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. Like classes, modules are bundles of methods and constants. Unlike classes, modules don’t have instances; instead, you specify that you want the functionality of a particular module to be added to the functionality of a class or of a specific object.

The greatest strength of modules is that they help with program design and flexibility. You’ll see evidence of this both in examples of modules you can write

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required