Sometimes it’s useful to set a default value for a Struct. If either value is empty it will return the default value specified after the || operator.
require 'date'
DateRange = Struct.new(:start_date, :end_date) do
def start_date
self[:start_date] || Date.today - 30.days
end
def end_date
self[:end_date] || Date.today
end
end