Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2013 13:02
Show Gist options
  • Save anonymous/6580417 to your computer and use it in GitHub Desktop.
Save anonymous/6580417 to your computer and use it in GitHub Desktop.
Fizz Buzz Steps 1-4
class FizzBuzz
require 'json'
def initialize (input)
@max = input
end
def modulo_parse (n)
if n % 15 == 0
"fizzbuzz"
elsif n % 5 == 0
"buzz"
elsif n % 3 == 0
"fizz"
else
n.to_s
end
end
def fizzbuzzer
(1..@max).map do |n|
modulo_parse (n)
end
end
def as_text ()
fizzbuzzer().join(", ")
end
def as_json
fizzbuzzer().to_json
end
def as_html
<<-EOF
<html>
<body>
#{(1..@max).map {|n| "<li> #{modulo_parse(n)} </li>"}.join("\n\t")}
</body>
</html>
EOF
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment