-
-
Save benaskins/47278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BONUS PARTY GAME - Choose 1 or make your own! Is this DRY gone mad? | |
# A | |
named_scope :leads, :conditions => ["dancers.lead = ?", true], :joins => :dancer | |
named_scope :follows, :conditions => ["dancers.lead = ?", false], :joins => :dancer | |
# B | |
[ | |
[:leads, true], | |
[:follows, false] | |
].each do |role, data| | |
named_scope name, :conditions => ["dancers.lead = ?", data], :joins => :dancer | |
end | |
# C | |
lambda {|role_conditions| | |
named_scope :leads, role_conditions[true] | |
named_scope :follows, role_conditions[false] | |
}[lambda {|x| { | |
:conditions => ["dancers.lead = ?", x], | |
:joins => :dancer | |
}}] | |
# D | |
with(L{|x| {:conditions => ["dancers.lead = ?", x], :joins => :dancer}}) do |f| | |
named_scope :leads, f[true] | |
named_scope :follows, f[false] | |
end | |
# E | |
named_scope :with_role, lambda { |role| :conditions => ["dancers.lead = ?", role == :lead ? true : false], :joins => :dancer } | |
# eg. | |
Partner.with_role(:lead) | |
Partner.with_role(:follow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment