-
-
Notifications
You must be signed in to change notification settings - Fork 23
Update ruby/clock example solution to match style guide #83
base: master
Are you sure you want to change the base?
Conversation
The [ruby style guide](https://github.com/rubocop-hq/ruby-style-guide#sprintf) currently suggests to use `format` or `sprintf` instead of `String#%`. In addition, the `self` in the hash method is redundant, the [style guide](https://github.com/rubocop-hq/ruby-style-guide#no-self-unless-required) also recommends not including it here.
Thanks for the suggestion :) I personally disagree with the rubocop style guide on this one. I think |
I agree with both: that |
@iHiD I prefer the |
@kotp Yes. I agree with you. @isen0011 What do you think about not changing the code, but adding a discussion point on this instead? I feel that @F3PiX Would you be happy with that? |
Specifically being called on a String object, even. |
@iHiD, that makes sense to me. I had thought that |
@@ -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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 😊 🏵️ :
There was a problem hiding this comment.
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.
The ruby style guide currently suggests to use
format
orsprintf
instead ofString#%
.In addition, the
self
in the hash method is redundant, the style guide also recommends not including it here.