《Metaprogramming Ruby》学习笔记二 之 Class Definitions
The Current Class
In a class definition,the current object self is the class being defined, the current class is the same as self
All methods defined with def become instance methods of the current class.
If you have a reference to the class, you can open the class with
The Current Class and Special Cases
ths current class is MyClass
Class Instance Variables
different from Class Instance Variables, they can be accessed by subclasses and by regular instance methods.
a nasty habit that make it be shuned by Class Instance Variables
Methods that are defined on class Module, you can use them whenever self is a module or a class.
Class Macros look like keywords, but they're just regular class methods that are meant to be used in a class definition
Method Lookup and eigenclasses
Eigenclasses and Inheritance
Class attributes live in the class's eigenclass
a shortcut that includes a module in the receiver's eigenclass
When you redefind a method, you don't really change the method.Instead, you define a new method add attach an existing name to that new method.
write an Around Alias in three simple steps alias a method; rededine it; call the old method from the new method