From: John Kriple Date: 2009-10-04T05:47:13+09:00 Subject: Re: Writing a Mad Libs program? > $ ruby madlib.rb madlib.txt I am using nano for a script shell. Does that have an effect on this? > Give me a gemstone: > Ruby > Give me a gemstone: > Emerald Where does this get written? > madlib > Our favorite language is Ruby. We think Ruby is better > than Emerald. So, I guess my biggest question is where does the script get written before you start writing the program to fill in the gaps? > $ cat madlib.rb > def ask_for(str) > puts "Give me #{str}:" > $stdin.gets.chomp > end > > keys={} > > puts "", ARGV[0].split(".")[0].gsub("_", " "), > IO.read(ARGV[0]).gsub(/\(\(([^)]+)\)\)/) { > if (t=$1) =~ /\A([^:]+):(.+)\z/ > keys[$1]=ask_for($2) > else > keys[t] || ask_for(t) > end > } > $ cat madlib.txt > Our favorite language is ((gem:a gemstone)). We think ((gem)) is better > than ((a gemstone)). > > Hope that helps. > > James Edward Gray II -- Posted via http://www.ruby-forum.com/.