Active Support Concerns

I recently came across this inherent feature Rails provides to modularize or break down huge ActiveRecord models into reusable chunks or concerns. This way, these concerns are now pluggable into several different models where there would be a need for them. Not sure how many folks out there are aware of this nice little thing. I did’nt for sure until couple of days ago.

module Pluggable
extend ActiveSupport::Concern

included do
extend ClassMethods
include InstanceMethods
end

module ClassMethods

end

module InstanceMethods

end
end

class Plug
include Pluggable
end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s