Last active
March 23, 2017 13:56
-
-
Save daveyarwood/3228f040f136d15e5445b39d24a8984e 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
#!/usr/bin/env ruby | |
template = <<~HEREDOC | |
{{plural noun}} are {{color}}, | |
{{plural noun}} are {{color}}, | |
{{food}} is {{adjective}}, | |
and so are you. | |
HEREDOC | |
def prompt(type) | |
print type << ': ' | |
gets.chomp | |
end | |
def replace_fields(template) | |
template.scan(/{{([^}]+)}}/).flatten.inject(template) do |result, type| | |
result.sub "{{#{type}}}", prompt(type) | |
end | |
end | |
madlib = replace_fields(template) | |
puts | |
puts madlib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment