I
Isaac Toothyxdip
Isaac said:Thanks that works!
but one thing i dont really get what is going on with (gets.scan
/[\w'-]*/) - [""] ?
could you explain it? like every party i under stand the gets and i
guess the scan reads whats entered but i dont really understand the
/[\w-]*/) then i guess the - [""] is the array that what ever is
scanned is added to
actually this doesnt work the way i want it to.
when i try to retrieve and array from that i think that the scan thing
returns it as a integer other then the string i need why is this?
this is the code that im using to do this:
places = ['first', 'second', 'third', 'fourth', 'fifth']
puts 'Please enter 5 words on the same line with spaces then press
enter:'
answered = false
while not answered
input_words = (gets.scan /[\w-]*/) - [""]
if input_words.length > 5
puts "Please type in FIVE words no more: "
else
answered = true
end
end
input_words.each_with_index do |word, i|
puts "To view a word you picked type:\n 1: first word\n 2: second
word\n 3: third word\n 4: fourth word\n 5: fifth word"
answered = false
while not answered
num_answer = gets.chomp
case num_answer[0]
when '1'[0]
i = 0
answered = true
when '2'[0]
i = 1
answered = true
when '3'[0]
i = 2
answered = true
when '4'[0]
i = 3
answered = true
when '5'[0]
i = 4
answered = true
else
puts "Try again...enter a number 1 - 5 to see one of the words
you typed"
end
end
puts "The %s word you entered was %s" % [places, word]
end