From: Todd Benson Date: 2008-02-21T07:57:42+09:00 Subject: Re: displaying user inputed arrays On Wed, Feb 20, 2008 at 3:56 PM, Isaac Toothyxdip wrote: > Isaac Toothyxdip wrote: > > 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 a, n = nil puts "Please enter 5 words" until (a = (gets.scan /[\w'-]*/) - [""]).length == 5 puts "Please type in exactly FIVE words, thanks." end puts "You would like to print out which word number? (1-5)" until (1..5).include? (n = gets.chomp.to_i) puts "Please pick a number 1 through 5" end puts a[n - 1] Todd