Last Updated: June 22, 2016
·
308
· debbora

Ruby | include x extend

Module A
   def say
      puts "Hello! I'm module A"
   end
 end

 class B
   include A
 end

 class C
   extend A
 end

Class method

B.say produces: undefined method 'say' for B:Class

C.say produces: this is module A


Instance method

B.new.say produces: this is module A

C.new.say produces: undefined method 'say' for C:Class