Skip to content

Instantly share code, notes, and snippets.

@stulentsev
Last active October 25, 2017 12:13
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 stulentsev/b7fc3830c9d21a115308f275111cf549 to your computer and use it in GitHub Desktop.
Save stulentsev/b7fc3830c9d21a115308f275111cf549 to your computer and use it in GitHub Desktop.
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