Created
November 27, 2019 14:59
-
-
Save cyrilchampier/e5c7f403cb304aa8e9b09aca46600f45 to your computer and use it in GitHub Desktop.
include/extend/prepend simple
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
module KlassIncluded | |
def truc | |
puts "KlassIncluded::truc" | |
super | |
end | |
end | |
module KlassExtended | |
def truc | |
puts "KlassExtended::truc" | |
super | |
end | |
end | |
module KlassPrepended | |
def truc | |
puts "KlassPrepended::truc" | |
super | |
end | |
end | |
class Klass | |
include KlassIncluded | |
extend KlassExtended | |
prepend KlassPrepended | |
def self.truc | |
puts "Klass.self::truc" | |
super | |
end | |
def truc | |
puts "Klass::truc" | |
super | |
end | |
end | |
puts "Klass.ancestors #{Klass.ancestors}" | |
puts Klass.new.truc | |
puts "Klass.singleton_class.ancestors #{Klass.singleton_class.ancestors}" | |
puts Klass.truc | |
puts "good?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment