Created
May 16, 2013 05:40
-
-
Save treble37/5589616 to your computer and use it in GitHub Desktop.
Playing with mad libs in ruby....
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
sentence_library=["I had a ((an adjective)) sandwich for lunch today. It dripped all over my ((a body part)) and ((a noun)).", | |
"Our favorite language is ((gem:a gemstone)). We think ((gem)) is better than ((a gemstone))."] | |
#token_arr = sentence.scan(/\(\(([^)]+)\)\)/) | |
sentence = sentence_library[rand(sentence_library.size)] | |
token_arr = sentence.scan(/\(\(.*?\)\)/) | |
hsh = {} | |
token_arr.each do |t| | |
puts "Enter a word for #{t.delete('()')}?" | |
hsh[t] = gets.chomp | |
end | |
hsh.each do |key,val| | |
sentence.gsub!(key,val) | |
end | |
p sentence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment