Last active
October 25, 2017 12:13
-
-
Save stulentsev/b7fc3830c9d21a115308f275111cf549 to your computer and use it in GitHub Desktop.
This file contains 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 Proc | |
def and(other_proc) | |
->(*args) { call(*args) && other_proc.call(*args) } | |
end | |
end | |
def word_or_number(n) | |
div3 = ->(x) { x.modulo(3).zero? } | |
div5 = ->(x) { x.modulo(5).zero? } | |
case n | |
when div3.and(div5) then 'fizzbuzz' | |
when div3 then 'fizz' | |
when div5 then 'buzz' | |
else n.to_s | |
end | |
end | |
puts (1..20).map(&method(:word_or_number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment