Skip to content

Instantly share code, notes, and snippets.

@mikamix
Last active September 15, 2015 15:49
Show Gist options
  • Save mikamix/e26a5696e427844784bb to your computer and use it in GitHub Desktop.
Save mikamix/e26a5696e427844784bb to your computer and use it in GitHub Desktop.
class Num
def initialize(v)
@v = v
end
def combine(target)
target
end
end
class FizzBuzz
attr_reader :v
def initialize(v)
@v = v
end
def combine(target)
FizzBuzz.new(@v + target.v)
end
end
def fizzbuzz(n)
fizz = [n].select { |e| e % 3 == 0 }.map { FizzBuzz.new('Fizz') }
buzz = [n].select { |e| e % 5 == 0 }.map { FizzBuzz.new('Buzz') }
fizz.concat(buzz).inject Num.new(n) do |x, y|
x.combine(y)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment