Created
December 11, 2014 21:15
-
-
Save NullVoxPopuli/835487b4ec1f679d6a20 to your computer and use it in GitHub Desktop.
shows what happens to the ancestry if a class - and the super classes
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
require "pry-byebug" | |
module ToBeIncluded | |
end | |
module ToBePrepended | |
end | |
class Super | |
end | |
class SuperIncluded | |
include ToBeIncluded | |
end | |
class SuperPrepended | |
prepend ToBePrepended | |
end | |
class A | |
include ToBeIncluded | |
end | |
class B | |
prepend ToBePrepended | |
end | |
class SubA < Super | |
include ToBeIncluded | |
end | |
class SubB < Super | |
prepend ToBePrepended | |
include ToBeIncluded | |
end | |
class SubC < SuperIncluded | |
prepend ToBePrepended | |
end | |
class SubD < SuperPrepended | |
include ToBeIncluded | |
end | |
binding.pry | |
puts "debug!" | |
# use .ancestors | |
# [1] pry(main)> A.ancestors | |
# => [A, ToBeIncluded, Object, PP::ObjectMixin, Kernel, BasicObject] | |
# [2] pry(main)> B.ancestors | |
# => [ToBePrepended, B, Object, PP::ObjectMixin, Kernel, BasicObject] | |
# [3] pry(main)> Sub.ancestors | |
# NameError: uninitialized constant Sub | |
# from (pry):3:in `<main>' | |
# [4] pry(main)> SubA.ancestors | |
# => [SubA, ToBeIncluded, Super, Object, PP::ObjectMixin, Kernel, BasicObject] | |
# [5] pry(main)> SubB.ancestors | |
# => [ToBePrepended, SubB, ToBeIncluded, Super, Object, PP::ObjectMixin, Kernel, BasicObject] | |
# [6] pry(main)> SubC.ancestors | |
# => [ToBePrepended, SubC, SuperIncluded, ToBeIncluded, Object, PP::ObjectMixin, Kernel, BasicObject] | |
# [7] pry(main)> SubD.ancestors | |
# => [SubD, ToBeIncluded, ToBePrepended, SuperPrepended, Object, PP::ObjectMixin, Kernel, BasicObject] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment