Created
June 21, 2017 11:51
-
-
Save RobertDober/4e2599d2af9ab5186e34d4dfa0e0952e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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