Last active
November 8, 2015 19:54
-
-
Save jclosure/b34753a2a781487a33a4 to your computer and use it in GitHub Desktop.
Programmatically determine if a class is a singleton_class.
This file contains 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
x = MyClass | |
# pre ruby 2.0 | |
def eigenclass? | |
Class === x && x.ancestors.first != x | |
end | |
# post ruby 2.0 | |
def eigenclass? | |
Class === x && !x.ancestors.include?(x) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment