Summary
This chapter aimed to provide you with the knowledge necessary to create modules with the Ruby object model. We have added instance methods by including modules into classes. We have added class methods to extend class functionality. We have created namespaces for our modules. As a very crucial part, we have made a distinction between prepending modules into classes and how you can extend and include functionality. Modules in Ruby accomplish multiple purposes such as creating namespaces, creating reusable class and instance methods, and modifying a class's code at runtime. Modules are Ruby's answer to multiple inheritance, in that they allow classes to incorporate code from multiple sources. As we saw in the last section, when a module is included or prepended, it affects the class hierarchy, which is what Ruby uses to do method lookup and dispatch. The ordering of this hierarchy is important and something to keep in mind as you start using third-party modules in...