Never been to DZone Snippets before?

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 (See related posts)

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



You need to create an account or log in to post comments to this site.


Click here to browse all 7284 code snippets

Related Posts