Created
March 15, 2024 03:59
-
-
Save budu/3b27c88476f4dbb5f19e1e8061bf6102 to your computer and use it in GitHub Desktop.
Quick Ruby implementation of Exercism Clock exercise
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
Clock = Data.define :hours, :minutes do | |
def initialize(hours:, minutes:) | |
super hours: (hours + minutes / 60) % 24, minutes: minutes % 60 | |
end | |
def add_minutes(minutes) = self.class.new(hours, self.minutes + minutes) | |
def to_s = '%02d:%02d' % [hours, minutes] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Translated from https://exercism.org/tracks/rust/exercises/clock/iterations