Created
October 7, 2015 02:44
-
-
Save kangkyu/f349e350da0f5066dabb to your computer and use it in GitHub Desktop.
Go Mobs!
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(hours=0, minutes=0) | |
new(hours, minutes) | |
end | |
def initialize(hours=0, minutes=0) | |
array = minutes.divmod 60 | |
@minutes = array[1] | |
@hours = array[0] + hours | |
end | |
def ==(other) | |
seconds == other.seconds | |
end | |
def seconds | |
(@hours * 60 * 60) + (@minutes * 60) | |
end | |
def to_s | |
hour_string = @hours.to_s.rjust(2, "0") | |
minute_string = @minutes.to_s.rjust(2, "0") | |
"#{hour_string}:#{minute_string}" | |
end | |
def + minutes | |
@minutes += minutes | |
num, @minutes = @minutes.divmod 60 | |
@hours = num + @hours | |
@hours = @hours % 24 | |
self | |
end | |
def - minutes | |
@minutes -= minutes | |
puts "minutes :#{@minutes} hours :#{@hours}" | |
num, @minutes = @minutes.divmod 60 | |
puts "minutes :#{@minutes} hours :#{@hours}" | |
@hours = num + @hours | |
puts "minutes :#{@minutes} hours :#{@hours}" | |
@hours = @hours % 24 | |
puts "minutes :#{@minutes} hours :#{@hours}" | |
self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment