Skip to content

Instantly share code, notes, and snippets.

@284km
Created July 22, 2015 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 284km/3a5f3ff68c6d540f13f4 to your computer and use it in GitHub Desktop.
Save 284km/3a5f3ff68c6d540f13f4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class Fixnum
def fizzbuzz
return self if !fizz? && !buzz
[fizz, buzz].compact.join
end
private
def fizz
"fizz" if fizz?
end
def buzz
"buzz" if buzz?
end
def fizz?
self % 3 == 0
end
def buzz?
self % 5 == 0
end
end
class FizzBuzz
def self.call(*args)
new(*args).call
end
def initialize(max)
@max = max
end
def call
puts 1.upto(@max).map(&:fizzbuzz)
end
end
eval DATA.read
__END__
FizzBuzz.call(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment