Skip to content

Instantly share code, notes, and snippets.

View kklimuk's full-sized avatar

Kirill Klimuk kklimuk

View GitHub Profile
memoized
def users_with_discounts(scoped_to={})
users = User.includes(payment_plan: :discounts).where(paying: true, **scoped_to).to_a
users.select do |users|
users.payment_plan.discounts.any? && !users.payment_plan.delayed?
end
end
def users_with_discounts
return @users_with_discounts unless @users_with_discounts.nil?
@users_with_discounts = computation_that_returns_nil || false
end
def users_with_discounts
@users_with_discounts ||= computation_that_returns_nil
end
def users_with_discounts(scoped_to={})
@users_with_discounts ||= {}
return @users_with_discounts[scoped_to] if @users_with_discounts.has_key?(scoped_to)
users = User.includes(payment_plan: :discounts).where(
paying: true,
**scoped_to
).to_a
@users_with_discounts[scoped_to] = users.select do |users|
def users_with_discounts
return @users_with_discounts unless @users_with_discounts.nil?
users = User.includes(payment_plan: :discounts).where(paying: true).to_a
@users_with_discounts = users.select do |users|
users.payment_plan.discounts.any? && !users.payment_plan.delayed?
end
end
def users_with_discounts
@users_with_discounts ||= User.includes(payment_plan: :discounts).where(paying: true).to_a
end
def users_with_discounts
User.includes(payment_plan: :discounts).where(paying: true).to_a
end