Skip to content

Instantly share code, notes, and snippets.

@cyrilchampier
Created November 27, 2019 14:58
Show Gist options
  • Save cyrilchampier/37d84325dba3026169b5a9ef3a5979b2 to your computer and use it in GitHub Desktop.
Save cyrilchampier/37d84325dba3026169b5a9ef3a5979b2 to your computer and use it in GitHub Desktop.
include/extend/prepend
module Mincluded
def toto
puts 'Mincluded#toto'
end
module Mprepended
def toto
puts 'Mprepended#toto'
end
end
def self.included(base)
base.prepend(Mprepended)
end
end
module Mextended
def toto
puts 'Mextended#toto'
end
end
class A
include Mincluded
extend Mextended
end
A.ancestors
A.singleton_class.ancestors
A.toto
A.new.toto
module Extensions
module ClassMethods
def bar
'Extended Bar!'
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment