Skip to content

Instantly share code, notes, and snippets.

@saxxi
Last active August 29, 2015 14:27
Show Gist options
  • Save saxxi/2b3fa8c24e201f5c78ae to your computer and use it in GitHub Desktop.
Save saxxi/2b3fa8c24e201f5c78ae to your computer and use it in GitHub Desktop.
Classic FizzBuzz in Ruby
class FizzBuzz
def dump(total_numbers)
total_numbers.times do |i|
puts parse_string i + 1
end
end
def parse_string(number)
is_divisible_by_3 = number % 3 == 0
is_divisible_by_5 = number % 5 == 0
if is_divisible_by_3 && is_divisible_by_5
"FizzBuzz"
elsif is_divisible_by_3
"Fizz"
elsif is_divisible_by_5
"Buzz"
else
number
end
end
end
FizzBuzz.new.dump(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment