Skip to content
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
7 changes: 7 additions & 0 deletions 01.fizzbuzz/fizzbuzz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(1..20).each { |n|

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rubyのeachにブロックを渡すとき、複数行の場合は{}ではなくdo...endを使うのが慣例です。

(1..20).each do |n|
  # ...
end

1行で書く場合は{}、複数行の場合はdo...endという使い分けを覚えておくと良いです。

(puts "FizzBuzz"; next) if n.modulo(3 * 5) == 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

行末に余分なスペースが入っています。エディタの設定で「保存時に行末スペースを削除する」をオンにしておくと、こういったものを自動で防げます。

また、n.modulo(3 * 5)n.modulo(15) と書けますし、% 演算子を使って n % 15 == 0 と書くこともできます。どちらがより読みやすいか意識してみてください。

(puts "Buzz"; next) if n.modulo(5) == 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2行目と同様、行末に余分なスペースが入っています。

(puts "Fizz"; next) if n.modulo(3) == 0
puts n

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

行末に余分なスペースが入っています。こちらも合わせて取り除いてください。

}