Skip to content

Instantly share code, notes, and snippets.

@jclosure
Last active November 8, 2015 19:54
Show Gist options
  • Save jclosure/b34753a2a781487a33a4 to your computer and use it in GitHub Desktop.
Save jclosure/b34753a2a781487a33a4 to your computer and use it in GitHub Desktop.
Programmatically determine if a class is a singleton_class.
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