From: Todd Benson Date: 2008-02-21T08:33:48+09:00 Subject: Re: displaying user inputed arrays On Wed, Feb 20, 2008 at 4:57 PM, Todd Benson wrote: > > 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'-]*/) - [""] ? scan /[\w'-]*/ ...returns an array of everything that matches the regular expression /[\w'-]*/ This returns every string that has zero or more of a word character (\w), an apostrophe ('), or a hyphen (-). The - [""] part is to subtract all empty strings from the array. I just noticed, however, though that you can omit that last bit if you use /[\w'-]+/ instead (the + instead of the *). That scans for _one_ or more, instead of _zero_ or more characters. Same code, but the scan changed... 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