Skip to content

Instantly share code, notes, and snippets.

@classicvalues
Forked from therabidbanana/hello_world.rb
Created August 21, 2021 03:54
Show Gist options
  • Save classicvalues/3276d69e72de9ee1dd3362b350d53b2e to your computer and use it in GitHub Desktop.
Save classicvalues/3276d69e72de9ee1dd3362b350d53b2e to your computer and use it in GitHub Desktop.
An extremely convoluted hello world
#!/usr/bin/env ruby
require 'yaml'
# Prints out the string "Hello World!" in
# an extremely convoluted way involving
# method_missing magic, dynamic method calls,
# some metaprogramming, completely useless comments,
# the DATA block, yaml, and Sesame Street.
#
# This hello world brought to you by the letter Q.
module TheAnswer
def self.letters(*args)
args.each do |letter|
class_eval(<<-DOC
def #{letter}; ?#{letter}; end
DOC
)
end
end
letters :a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m
letters :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z
# Now I know my abc's...
def method_missing(arg, *args)
me = "*"[0].to_s # Find the answer in the stars.
class << me
# What kind of cruel joke is this nonsense?
def _?; to_i(j - a); end
def _!; to_i(o - b); end
def __; to_i(k - c); end
def _*; to_i(e - d); end
end
me.send(arg, *args)
end
def Say(arg)
puts arg
end
end
include TheAnswer
# Load some data
brain = YAML::load(DATA)
# Do something silly by injecting an empty string into the brain
something_silly = brain.inject("") do |data, obj|
data +=
# Use the case keyword twice for double the fun.
case my = case obj["words"].size
when d - a
# Get the letter of the day
obj["letter_of_day"]
when c + b - (2 * a + 1)
# Subtract a number from some other numbers added together mod another number
(_? - (obj["number_of_day"] + obj["episode"]) % _!)
else
__ - b + a # Adjust the answer for rounding error
end
# My oh my, I have no idea what is going on.
when String; my; else; my.chr; end
end
Say(something_silly)
__END__
---
-
episode: 4001
letter_of_day: H
number_of_day: 12
words:
- Hide
- Happy
- Hairy
-
episode: 4000
letter_of_day: e
number_of_day: 1
words:
- Eat
- Elephant
- Emu
-
episode: 3981
letter_of_day: l
number_of_day: 3
words:
- la
- Laugh
- Lead
-
episode: 4161
letter_of_day: l
number_of_day: 4
words:
- Laundry
- Little
- Late
-
episode: 4070
letter_of_day: o
words:
- Oh
- Odd
- Otter
-
episode: 3988
letter_of_day: Y
number_of_day: 14
words:
- Yak
- Yellow
-
episode: 3992
letter_of_day: W
number_of_day: 2
words:
- Walrus
- Waldo
- Wall
-
episode: 3983
letter_of_day: o
number_of_day: 19
words:
- Oatmeal
- Ostrich
- Oboe
-
episode: 3995
letter_of_day: r
number_of_day: 15
words:
- Rap
- Radio
- Rat
-
episode: 4203
letter_of_day: l
words:
- Large
- Label
- Letter
-
episode: 3990
letter_of_day: d
number_of_day: 7
words:
- Don't
- Dessert
- Do
-
episode: 3984
letter_of_day: m
number_of_day: 17
words:
- Mother
- Mad
- Milk
- Marker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment