Created
June 20, 2016 23:48
-
-
Save dcmorse/21860a9664ff434aab21a755b763c304 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
=begin | |
Class Hierarchy | |
A | |
/ \ | |
B1 B2 | |
/ \ | |
C1 C2 | |
=end | |
class A | |
def self.inherited(sub) | |
puts "A has new descendant #{sub}" | |
end | |
end | |
class B1 < A | |
end | |
class C1 < B1 | |
end | |
class B2 < A | |
def self.inherited(sub) | |
puts "B2 has new descendant #{sub}" | |
end | |
end | |
class C2 < B2 | |
end | |
# actual output: | |
=begin | |
A has new descendant B1 | |
A has new descendant C1 | |
A has new descendant B2 | |
B2 has new descendant C2 | |
=end | |
# well designed OO language output: | |
=begin | |
A has new descendant B1 | |
A has new descendant C1 | |
A has new descendant B2 | |
B2 has new descendant C2 | |
A has new descendant C2 <- ! | |
=end | |
=begin | |
'A' needs self.inherited to work, regardless of what it's subtypes | |
decide to put class methods on. This is one gist where I think the ruby | |
object system is silly. | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment