Martin, I believe I've successfully written the first portion of Chris
Pine's "Deaf Grandma" exercise. With the help of the stuff you posted
about the various approaches to take to break a loop & various people on
#ruby-lang (particularly Giraph), I've fulfilled the majority of my
goal, which turned out to be quite a frustrating task. Although the text
being outputted suggests that you are speaking to Grandma through an
intermediary (at first), the main idea is still heavily rooted in what
is said & how user input is replied to. This is the finished program, &
as you can tell, I've implemented various things from the suggestions
given in posts on here & in #ruby-lang. I'm most proud of the fact that
it's as if Grandma & her intermediary are talking to you in real-time...
the effect is nice. So, here's the code for the finished program (void
of the extension, which I will work on tomorrow):
==========
def granny_says(str)
str.each_byte do |byte|
print byte.chr
sleep 0.05
STDOUT.flush
end
puts
STDOUT.flush
end
while true do
granny_says("Got a question for granny? Make sure to")
granny_says("input yo' question in all caps, or else")
granny_says("granny can't hear ya'!\n\n")
reply = gets.chomp
if (reply == reply.upcase)
random = rand(21) + 1930
granny_says("\nNo, not since #{random}!")
granny_says("That's all the time I've got, child!")
granny_says("Hasta la-bye-bye!")
break
else
granny_says("\nGranny can't hear you! Wanna know why?")
granny_says("'Cause that wasn't in all caps, yo'!")
granny_says("So, I'll repeat what I said before ...\n\n")
end
end
==========
Now that I've got that squared away, I'll look into adding the extension
to the exercise. & to tell you the truth, I've no idea how to do that.
I'm thinkin' I need to create another loop, & define (some how, I'm
still not sure) that Grandma will only say goodbye after the user has
inputted "bye" three times in a row. I guess I have an inkling of an
idea of how to go about it, just not sure it'll work. If all goes well,
I'll be posting later tomorrow with the total exercise, extension
included, complete. Wish me luck!
--
Posted via http://www.ruby-forum.com/.