Skip to content

Instantly share code, notes, and snippets.

@budu
Created March 15, 2024 03:59
Show Gist options
  • Save budu/3b27c88476f4dbb5f19e1e8061bf6102 to your computer and use it in GitHub Desktop.
Save budu/3b27c88476f4dbb5f19e1e8061bf6102 to your computer and use it in GitHub Desktop.
Quick Ruby implementation of Exercism Clock exercise
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
@budu
Copy link
Author

budu commented Mar 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment