Created
November 27, 2019 14:58
-
-
Save cyrilchampier/37d84325dba3026169b5a9ef3a5979b2 to your computer and use it in GitHub Desktop.
include/extend/prepend
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 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