Skip to content

Instantly share code, notes, and snippets.

@JonathanWThom
Created August 30, 2019 00:46
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 JonathanWThom/8f55730450507e6da7329ce6991d750d to your computer and use it in GitHub Desktop.
Save JonathanWThom/8f55730450507e6da7329ce6991d750d to your computer and use it in GitHub Desktop.
Prompt: What is the most complex and unreadable way you can write FizzBuzz?
(1..100).each do |i|
[3, 5].each do |num|
define_method("klass_#{num}") do
Class.new do
if i % num == 0
define_method("#{i}") do
call
end
end
def call
self.class.name
end
end
end
end
fizz = Object.const_set(:Fizz, klass_3)
buzz = Object.const_set(:Buzz, klass_5)
result = [fizz.new, buzz.new].map do |klass|
begin
klass.send("#{i}")
rescue
end
end.compact
if result.empty?
puts i
else
puts result&.join("")
end
Object.send(:remove_const, :Fizz)
Object.send(:remove_const, :Buzz)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment