LoginSignup
6
2

More than 3 years have passed since last update.

クソコードあるあるを詰め込んだ「ひどいFizzBuzz」を書きました。

Posted at

タイトルの通りです。
コードレビューの練習などにお使いください。

hidoi_fizzbuzz.rb
print "数字を入力してください:"
# 入力された数字をnに代入する。
n = gets.chomp.to_i

result = ""
number = 0

# 3の倍数かどうかを判定する。余りが0ならtrue、そうでなければfalse。
def fizz?(number)
  result = true
  if number % 3 == 0 then
    result = true
  else
    result = false
  end

  return result
end

# 3の倍数かどうかを判定する。余りが0ならtrue、そうでなければfalse。
def judge_buzz?(n)
  result = true
  if n % 5 == 0 then
    result = true
  else
    result = false
  end

  return result
end

# def fizzbuzz?(n)
#   result = true
#   if n % 15 == 0 then
#     result = true
#   else
#     result = false
#   end
#   return result
# end

# fizzbuzzを表示
if fizz?(n) == true then
  if judge_buzz?(n) == true then
      result = "fizzbuzz"
      puts result
    else
      result = "fizz"
      puts result
    end

elsif judge_buzz?(n) == true then

  result = "buzz"
  puts result
else
  puts n
end

(ちなみに僕はエンジニア歴1年程度のクソエンジニアです。こんなクソコードを実務で書いてしまわないように日々勉強しております・・・)

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2