Skip to content

Instantly share code, notes, and snippets.

@mariorcardoso
Last active June 25, 2017 11:44
Show Gist options
  • Save mariorcardoso/dc592344f8e40e56440c542bc020c640 to your computer and use it in GitHub Desktop.
Save mariorcardoso/dc592344f8e40e56440c542bc020c640 to your computer and use it in GitHub Desktop.
Code samples about value objects
class DateRange
attr_reader :start_date, :end_date
def initialize(start_date, end_date)
@start_date, @end_date = start_date, end_date
end
def include_date?(date)
date >= start_date && date <= end_date
end
def include_date_range?(date_range)
start_date <= date_range.start_date && end_date >= date_range.end_date
end
def overlap_date_range?(date_range)
start_date <= date_range.end_date && end_date >= date_range.start_date
end
def to_s
"from #{start_date.strftime('%d-%B-%Y')} to #{end_date.strftime('%d-%B-%Y')}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment