Created
June 30, 2016 07:41
-
-
Save tagomoris/a45c64a172d5a5f2f7b7798dd0ab1151 to your computer and use it in GitHub Desktop.
This file contains 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
class A | |
def foo | |
"a" | |
end | |
end | |
class B < A | |
def foo | |
v = super | |
"b#{v}" | |
end | |
end | |
module M | |
def foo | |
v = super | |
v.upcase | |
end | |
end | |
b1 = B.new.extend(M) | |
p b1.singleton_class.ancestors | |
p b1.foo | |
b2 = B.new | |
b2.singleton_class.include(M) | |
p b2.singleton_class.ancestors | |
p b2.foo | |
b3 = B.new | |
b3.singleton_class.prepend(M) | |
p b3.singleton_class.ancestors | |
p b3.foo |
This file contains 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
ruby hoge.rb | |
[#<Class:#<B:0x007f98b9962c70>>, M, B, A, Object, Kernel, BasicObject] | |
"BA" | |
[#<Class:#<B:0x007f98b99626a8>>, M, B, A, Object, Kernel, BasicObject] | |
"BA" | |
[M, #<Class:#<B:0x007f98b9962180>>, B, A, Object, Kernel, BasicObject] | |
"BA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment