Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Last active August 29, 2015 14:27
Show Gist options
  • Save kangkyu/14eb89318369bf375efe to your computer and use it in GitHub Desktop.
Save kangkyu/14eb89318369bf375efe to your computer and use it in GitHub Desktop.
def fizz(number)
number % 3 == 0 ? "fizz" : ""
end
def buzz(number)
number % 5 == 0 ? "buzz" : ""
end
def fizz_buzz(number)
(number.to_s + " " + fizz(number) + buzz(number))
.chomp(" ")
end
def run_fizz_buzz(limit)
(1..limit).each do |number|
puts fizz_buzz(number)
end
end
run_fizz_buzz(100)
@kangkyu
Copy link
Author

kangkyu commented Aug 13, 2015

Thank you @charliemcelfresh for your comment. I also made an additional change, I pulled out fizz and buzz as separate methods.

def fizz_buzz(number)
  ( number.to_s +
    " " +
    (number % 3 == 0 ? "fizz" : "") +
    (number % 5 == 0 ? "buzz" : "")
  ).chomp(" ")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment