Last active
April 2, 2018 14:32
-
-
Save r7kamura/4ea0e21125906ae242e1164ea49a61a1 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
module Fizz | |
def call(target, max, state) | |
if target % 3 == 0 | |
state << "fizz" | |
end | |
super | |
end | |
end | |
module Buzz | |
def call(target, max, state) | |
if target % 5 == 0 | |
state << "buzz" | |
end | |
super | |
end | |
end | |
module Printable | |
def call(target, max, state) | |
if state.empty? | |
puts target | |
else | |
puts state.join | |
end | |
super(target, max) | |
end | |
end | |
module Clearable | |
def call(target, max) | |
super(target, max, []) | |
end | |
end | |
class FizzBuzz | |
prepend Printable | |
prepend Buzz | |
prepend Fizz | |
prepend Clearable | |
alias_method :step, :call | |
def call(target, max) | |
if target != max | |
step(target + 1, max) | |
end | |
end | |
end | |
FizzBuzz.new.call(1, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inheritance tree
State map