module Base def print p 'base' end end class A # add method for instance include Base end A.new.print class B # add method for class extend Base end B.print class C # include module for singleton # the same like extend class << self include Base end end C.printinclude work the same as inheritance but its not the same:
- class have only one parent
- include extend only instance
# check include A.new.kind_of? Base #=> true # check extend B.kind_of? Base #=> true
No comments:
Post a Comment