Skip to content

Instantly share code, notes, and snippets.

@cardoni
Last active August 29, 2015 14:19
Show Gist options
  • Save cardoni/58daa93eb1f293a65c6d to your computer and use it in GitHub Desktop.
Save cardoni/58daa93eb1f293a65c6d to your computer and use it in GitHub Desktop.
quick ruby fizzbuzz
# encoding: UTF-8
class FizzBuzz
def initialize( times=100 )
@times = times.to_i
end
def count
( 1..@times ).count
end
def start
( 1..@times ).each do | number |
fizzbuzz( number )
end
end
def fizzbuzz( number )
number = number.to_i
result = ''
if number % 3 == 0
result += 'Fizz'
end
if number % 5 == 0
result += 'Buzz'
end
if result.empty?
result = number
end
puts "#{number}. #{result}"
end
end
fb = FizzBuzz.new()
# fb = FizzBuzz.new( 500 ) # or, pass more than 100 in....
puts "Count of items to print: #{fb.count}"
fb.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment