Skip to content

Instantly share code, notes, and snippets.

@eugeneius
Created September 1, 2014 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugeneius/884873965f90092fc50c to your computer and use it in GitHub Desktop.
Save eugeneius/884873965f90092fc50c to your computer and use it in GitHub Desktop.
Demonstrates how the behaviour of include and prepend on a singleton class differs between Ruby 2.0 and 2.1
module TestModule
end
class Included
class << self
include TestModule
end
end
class Prepended
class << self
prepend TestModule
end
end
p Included.singleton_class.ancestors
p Prepended.singleton_class.ancestors
# Ruby 2.0:
# [TestModule, Class, Module, Object, Kernel, BasicObject]
# [TestModule, #<Class:Prepended>, Class, Module, Object, Kernel, BasicObject]
# Ruby 2.1:
# [#<Class:Included>, TestModule, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject]
# [TestModule, #<Class:Prepended>, #<Class:Object>, #<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment