Skip to content

Instantly share code, notes, and snippets.

@cyrilchampier
Created November 27, 2019 14:59
Show Gist options
  • Save cyrilchampier/e5c7f403cb304aa8e9b09aca46600f45 to your computer and use it in GitHub Desktop.
Save cyrilchampier/e5c7f403cb304aa8e9b09aca46600f45 to your computer and use it in GitHub Desktop.
include/extend/prepend simple
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