DRYing associations and behavior
October 31st, 2007 • Uncategorized
module CommonBehaviour
def self.included(base)
base.class_eval <<-EOC
belongs_to :foo
has_many :bars
delegate :baz, :to => :survey_execution
EOC
base.send :include, InstanceMethods
end
module InstanceMethods
def bla
p 'bla'
end
end
end
class OneOfCommon < ActiveRecord::Base
include CommonBehaviour
end