Skip to content

Instantly share code, notes, and snippets.

@ipmsteven
Created February 10, 2015 06:43
Show Gist options
  • Select an option

  • Save ipmsteven/d81d364c4a120d5668bd to your computer and use it in GitHub Desktop.

Select an option

Save ipmsteven/d81d364c4a120d5668bd to your computer and use it in GitHub Desktop.
singleton_class in ruby
class B;end
class A < B;end
module C;end
module D;end
A.include C
C.include D
# A.ancestors
# => [A, C, B, Object, Kernel, BasicObject]
# A.singleton_class.ancestors
# => [#<Class:A>, #<Class:B>, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject]
# C.ancestors
# => [C, D]
# C.singleton_class.ancestors
# => [#<Class:C>, Module, Object, Kernel, BasicObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment