Designing Modules and Classes for Clarity and Reuse

When writing a program in Ruby, you organize your code into classes and modules. As we've seen, your efforts have to mesh with certain constraints in the way Ruby organizes and finds code at the class or module level and also at the disk file level.

But even in cases where it's going to be self-evident what to call the files and where to put them, you still have to make decisions about class and module hierarchies. A lot of that decision making has to do with deciding what should be a class and what should be a module.

Classes and modules are very closely related. In almost any case you could, if you felt like it, cut methods from a class, paste them into a module, and then mix the module into ...

Get Sams Teach Yourself Ruby in 21 Days now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.