Donโ€™t misuse modules and concerns

Because modules and concerns enable multiple-inheritance in Ruby, they can be a great way to share reusable functionality between classes. However, they can be misused.

Good ๐Ÿ”—

We should use concerns to:

module HasNotifications
  extend ActiveSupport::Concern

  included do
    has_many :notifications, dependent: :destroy, as: :notified
  end
end

class User
  include HasNotifications
end

class Company
  include HasNotifications
end

Bad ๐Ÿ”—

We should not use concerns to:

module UserExtensions
  module Notifications
    extend ActiveSupport::Concern

    included do
      has_many :notifications, dependent: :destroy
    end
  end
end

class User
  include UserExtensions::Notifications
end

Further reading ๐Ÿ”—