Skip to content

Instantly share code, notes, and snippets.

@mikhailov
Created September 26, 2015 16:52
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 mikhailov/93c9c19f5eb74f1edeaf to your computer and use it in GitHub Desktop.
Save mikhailov/93c9c19f5eb74f1edeaf to your computer and use it in GitHub Desktop.
FizzBuzz
class FizzBuzz
def initialize(array)
@array = array
@new_array = []
end
def process
@array.each do |e|
value = \
if e % 3 == 0 && e % 5 == 0
'FizzBuzz'
elsif e % 3 == 0
'Fizz'
elsif e % 5 == 0
'Buzz'
else
e
end
@new_array.push(value)
end
return @new_array
end
end
require 'minitest/autorun'
class FizzBuzzTest < Minitest::Unit::TestCase
def test_process
assert_equal [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz"], FizzBuzz.new((1..15).to_a).process
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment