Last active
September 15, 2015 15:49
-
-
Save mikamix/e26a5696e427844784bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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