RosettaCodeData/Task/Mad-Libs/Ruby/mad-libs.rb

14 lines
266 B
Ruby
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
puts "Enter a story, terminated by an empty line:"
story = ""
2015-02-20 00:35:01 -05:00
until (line = gets).chomp.empty?
2013-04-10 21:29:02 -07:00
story << line
end
story.scan(/(?<=[<]).+?(?=[>])/).uniq.each do |var|
print "Enter a value for '#{var}': "
2015-02-20 00:35:01 -05:00
story.gsub!(/<#{var}>/, gets.chomp)
2013-04-10 21:29:02 -07:00
end
2015-02-20 00:35:01 -05:00
puts
2013-04-10 21:29:02 -07:00
puts story