Created
February 13, 2012 01:57
-
-
Save xumingyong/1812724 to your computer and use it in GitHub Desktop.
Ruby: meta-programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #definition | |
| class Object < BasicObject | |
| include Kernel | |
| ... | |
| end | |
| #examples | |
| module M; end | |
| class C; include M; end | |
| C.ancestors # => [M, Object, Kernel, BasicObject] | |
| #eigenclass, metaclass or sington class is a hidden class for each object, | |
| #which only have one instance, where sington methods lives. | |
| #use following to define singleton class. | |
| class << self; self; end | |
| #1. superclass of metaclass of object is object's class | |
| #2. superclass of metaclass of class is metaclass of class's superclass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment