Conversation
pjord2026
reviewed
Jul 7, 2026
| @@ -0,0 +1,7 @@ | |||
| (1..20).each { |n| | |||
There was a problem hiding this comment.
Rubyのeachにブロックを渡すとき、複数行の場合は{}ではなくdo...endを使うのが慣例です。
(1..20).each do |n|
# ...
end1行で書く場合は{}、複数行の場合はdo...endという使い分けを覚えておくと良いです。
pjord2026
reviewed
Jul 7, 2026
| @@ -0,0 +1,7 @@ | |||
| (1..20).each { |n| | |||
| (puts "FizzBuzz"; next) if n.modulo(3 * 5) == 0 | |||
There was a problem hiding this comment.
行末に余分なスペースが入っています。エディタの設定で「保存時に行末スペースを削除する」をオンにしておくと、こういったものを自動で防げます。
また、n.modulo(3 * 5) は n.modulo(15) と書けますし、% 演算子を使って n % 15 == 0 と書くこともできます。どちらがより読みやすいか意識してみてください。
pjord2026
reviewed
Jul 7, 2026
| @@ -0,0 +1,7 @@ | |||
| (1..20).each { |n| | |||
| (puts "FizzBuzz"; next) if n.modulo(3 * 5) == 0 | |||
| (puts "Buzz"; next) if n.modulo(5) == 0 | |||
pjord2026
reviewed
Jul 7, 2026
| (puts "FizzBuzz"; next) if n.modulo(3 * 5) == 0 | ||
| (puts "Buzz"; next) if n.modulo(5) == 0 | ||
| (puts "Fizz"; next) if n.modulo(3) == 0 | ||
| puts n |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.