Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Update ruby/clock example solution to match style guide #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tracks/ruby/exercises/clock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Clock
end

def to_s
"%02d:%02d" % time.divmod(MINUTES_PER_HOUR)
format("%02d:%02d", *time.divmod(MINUTES_PER_HOUR))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style guide is only a guide. I prefer the original line as less noisy. Yes, somewhat mystical the first time you see it. Since we are talking about "Style Guide" I am thinking Rubocop here. It would also suggest not using double quotes, I believe. The single quotes help re-inforce that this is not some trick of "string interpolation" but rather substitution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the code when I dropped in, not realizing that I had already responded to the preference. 😊 🏵️ :

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to single quotes is an awesome idea! I did think it was a string interpolation trick, the first time I saw it. 👍 The single quotes are really meaningful here.

end

def +(other)
Expand All @@ -34,7 +34,7 @@ class Clock
alias eql? ==

def hash
[self.class, self.time].hash
[self.class, time].hash
end

protected
Expand Down