Skip to content

Instantly share code, notes, and snippets.

@mkweick
Created February 27, 2016 15:53
Show Gist options
  • Save mkweick/5a8f1d7076820e286d47 to your computer and use it in GitHub Desktop.
Save mkweick/5a8f1d7076820e286d47 to your computer and use it in GitHub Desktop.
Clock
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