Created
July 15, 2011 03:18
-
-
Save adam-e-trepanier/1083989 to your computer and use it in GitHub Desktop.
Singleton (eigen) class
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
| module Kernel | |
| # Returns the object's singleton class. | |
| def singleton_class | |
| class << self | |
| self | |
| end | |
| end unless respond_to?(:singleton_class) # exists in 1.9.2 | |
| # class_eval on an object acts like singleton_class.class_eval. | |
| def class_eval(*args, &block) | |
| singleton_class.class_eval(*args, &block) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment