B
Britt Hayes
How would I go about writing a 'Mad Libs' type program using Ruby?
Any examples would be greatly appreciated.
Thanks.
Any examples would be greatly appreciated.
Thanks.
How would I go about writing a 'Mad Libs' type program using Ruby?
Any examples would be greatly appreciated.
I had looked at those before, but I couldn't follow very well as I am
very new to Ruby.
Would you be able to get me started using one of those examples?
How does the mad lib script I wrote work with the commands?
$ ruby madlib.rb madlib.txt
Give me a gemstone:
Ruby
Give me a gemstone:
Emerald
madlib
Our favorite language is Ruby. We think Ruby is better
than Emerald.
$ 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
I am using nano for a script shell. Does that have an effect on this?
Where does this get written?
So, I guess my biggest question is where does the script get written
before you start writing the program to fill in the gaps?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.