Skip to content

Instantly share code, notes, and snippets.

@RobertDober
Created June 21, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertDober/4e2599d2af9ab5186e34d4dfa0e0952e to your computer and use it in GitHub Desktop.
Save RobertDober/4e2599d2af9ab5186e34d4dfa0e0952e to your computer and use it in GitHub Desktop.
class Calendar
class CalendarDate < ::Date
module IllegalDate
attr_reader :year, :month, :day
def to_s
"%d-%02d-%02d" % [year, month, day]
end
end
def self.new(*args)
super(*args)
rescue
o = allocate()
o.instance_exec do
@illegal = true
@year, @month, @day = args
extend IllegalDate
end
o
end
def legal?; !!!@illegal end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment