DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Sharing Has_many Extensions
Sometimes you extend an ActiveRecord association this way:
has_many :things do
def active
find :all, :conditions => ['active = ?', true]
end
end
You can share the same extensions using a lambda:
extensions = lambda {
def active
find :all, :conditions => ['active = ?', true]
end
}
has_many :things, &extensions
has_many :more_things, &extensions




