Skip to content

Instantly share code, notes, and snippets.

File 1
class Subscription::Plan
has_many :scan_frequencies
def scan_frequencies_sorted
scan_frequencies.sort do |a, b|
a.frequency.times_per_year <=> b.frequency.times_per_year
end
end
end
class Subscription::ScanFrequency
@jzellman
jzellman / gist:1711988
Created January 31, 2012 18:17
Var Args 10
class User < ActiveRecord::Base
# A user is active during a period if it has any subscriptions
# that are active during that period
def active?(start_date, end_date)
subscriptions.active_in_period(start_date, end_date).any?
end
end
# Lookup User and see if they are active
@jzellman
jzellman / gist:1711976
Created January 31, 2012 18:15
Var Args 9
class User < ActiveRecord::Base
# A user is only active if it has any subscriptions that are still active
def active?
subscriptions.active.any?
end
end
class AdminUser < User
# Admin users do not have subscriptions and are always active
def active?(*)
@jzellman
jzellman / gist:1711954
Created January 31, 2012 18:12
Var Args 8
class AdminUser < User
# Admin users do not have subscriptions and are always active
def active?(*)
true
end
end
@jzellman
jzellman / gist:1711952
Created January 31, 2012 18:11
Var Args 7
User.find(1).active?(start_date, end_date)
=> false
User.find(42).active?(start_date, end_date)
=> ArgumentError: wrong number of arguments (2 for 0)
@jzellman
jzellman / gist:1711948
Created January 31, 2012 18:10
Var Args 6
class User < ActiveRecord::Base
# A user is active during a period if it has any subscriptions that
#are active during that period
def active?(start_date, end_date)
subscriptions.active_in_period(start_date, end_date).any?
end
end
@jzellman
jzellman / gist:1711940
Created January 31, 2012 18:09
Var Args 5
User.find(1).active?
=> true
User.find(42).active?
=> true
@jzellman
jzellman / gist:1711934
Created January 31, 2012 18:08
Var Args 4
class User < ActiveRecord::Base
# A user is only active if it has any subscriptions that are still active
def active?
subscriptions.active.any?
end
end
class AdminUser < User
# Admin users do not have subscriptions and are always active
def active?
@jzellman
jzellman / gist:1711932
Created January 31, 2012 18:07
Var Args 3
# Always returns true, ignores arguments
def always_true(*)
true
end
always_true
=> true
always_true(false)
=> true