Created
September 1, 2014 05:32
-
-
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
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 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