Created
February 27, 2016 15:53
-
-
Save mkweick/5a8f1d7076820e286d47 to your computer and use it in GitHub Desktop.
Clock
This file contains hidden or 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 Clock | |
def self.at(hour, min = 0) | |
ClockTime.new(hour, min) | |
end | |
end | |
class ClockTime | |
attr_accessor :time | |
def initialize(hour, min) | |
@time = Time.new(2016,1,1, hour, min) | |
end | |
def to_s | |
time.strftime('%H:%M') | |
end | |
def +(min) | |
self.time += (min * 60) | |
self | |
end | |
def -(min) | |
self.time -= (min * 60) | |
self | |
end | |
def ==(other) | |
to_s == other.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment