Skip to content

Instantly share code, notes, and snippets.

@tamalw
Last active December 26, 2015 11:29
Show Gist options
  • Save tamalw/7144185 to your computer and use it in GitHub Desktop.
Save tamalw/7144185 to your computer and use it in GitHub Desktop.
Can I use "reverse" scopes on an instance to keep it DRY?
class Article < ActiveRecord::Base
scope :published, -> { where("draft = false AND publish_at <= ?", Time.now) }
end
foo = Article.find(123)
foo.published?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment