Skip to content

Instantly share code, notes, and snippets.

@ilnurnasyrov2
Last active April 2, 2017 20:47
Show Gist options
  • Save ilnurnasyrov2/e69f47081dffcf30a673537ea8f72496 to your computer and use it in GitHub Desktop.
Save ilnurnasyrov2/e69f47081dffcf30a673537ea8f72496 to your computer and use it in GitHub Desktop.
Fizz buzz without divison
require "active_support/core_ext/object/blank"
class FizzBuzzChecker
def initialize(point, point_name)
@point_name = point_name
@point = point
@current = 1
end
def check
if @current == @point
@current = 1
@point_name
else
@current += 1
nil
end
end
end
three = FizzBuzzChecker.new(3, "Fizz")
five = FizzBuzzChecker.new(5, "Buzz")
(1..100).each do |n|
puts [three.check, five.check].join.presence || n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment