class User attr_accessor :address_line1, :address_line2, :city, :state, :postal_code, :country def mailing_label label = [] label << address_line1 label << address_line2 label << "#{city}, #{state} #{postal_code}" label << country label.join("\n") end end
class Building attr_accessor :address_line1, :address_line2, :city, :state, :postal_code, :country def mailing_label label = [] label << address_line1 label << address_line2 label << "#{city}, #{state} #{postal_code}" label << country label.join("\n") end end
module Address attr_accessor :address_line1, :address_line2, :city, :state :postal_code, :country def mailing_label label = [] label << address_line1 label << address_line2 label << "#{city}, #{state} #{postal_code}" label << country label.join("\n") end end class User include Address end class Building include Address end
When we include a module in a class, we are basically copying the instance methods into a class.
While when a module is extended inside of a class, all of the methods that are defined as basic methods get extended into the class, meaning that they are added as class methods.