Skip to content

Instantly share code, notes, and snippets.

@Chryus
Created November 15, 2013 02:17
Show Gist options
  • Save Chryus/7478071 to your computer and use it in GitHub Desktop.
Save Chryus/7478071 to your computer and use it in GitHub Desktop.
Ruby fizzbuzz with each + case statement
(1..100).each do |x|
m3 = x.modulo(3) == 0
m5 = x.modulo(5) == 0
puts case
when (m3 and m5) then 'FizzBuzz'
when m3 then 'Fizz'
when m5 then 'Buzz'
else x
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment