Recipe 9.1. Simulating Multiple Inheritance with Mixins
Problem
You want to create a class that derives from two or more sources, but Ruby doesn't support
multiple inheritance.
Solution
Suppose you created a class called Taggable ...
Recipe 9.2. Extending Specific Objects with Modules
Credit: Phil Tomson
Problem
You want to add instance methods from a module (or modules) to specific
objects. You don't want to mix the module into the object's class, because you...
Recipe 9.3. Mixing in Class Methods
Credit: Phil Tomson
Problem
You want to mix class methods into a class, instead of mixing in instance methods.
Solution
The simplest way to accomplish this is to call extend on the class object, a...
Recipe 9.4. Implementing Enumerable: Write One Method, Get 22 Free
Problem
You want to give a class all the useful iterator and iteration-related features of Ruby's arrays (sort, detect, inject, and so on), but your class can't be a subcla...
Recipe 9.5. Avoiding Naming Collisions with Namespaces
Problem
You want to define a class or module whose name conflicts with an existing class or module, or you want to prevent someone else from coming along later and defining a class who...
Recipe 9.6. Automatically Loading Libraries as Needed
Problem
You've written a big library with multiple components. You'd like to split it up so that users don't have to load the entire library into memory just to use part of it. But you ...
Recipe 9.7. Including Namespaces
Problem
You want to use the objects within a module without constantly qualifying the object names with the name of their module.
Solution
Use include to copy a module's objects into the current names...
Recipe 9.8. Initializing Instance Variables Defined by a Module
Credit: Phil Tomson
Problem
You have a mixin module that defines some instance variables. Given a class that mixes in the module, you want to initialize the instance variable...
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.