Forum: Ruby on Rails Strench Error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Huseyin P. (Guest)
on 2006-04-06 13:49
I am new with ruby but something fishy with the array.
if I type
puts INV_FILE_HASH[q]   # where INV_FILE_HASH is my hash function
query is user input and couldbe 'aa' or 'aa aa'
query = query.split(/ /)
 query.each { |q|
  if (q == 'and')
  elsif (q == 'or')
    # q=aa at this point which is correct
    puts INV_FILE_HASH[q]    # prints out nil instead of values

I get "nil" where the query is 'aa' so the q is 'aa'.
 but if the query is 'aa aa' than q first run is 'aa' and second run is
'aa' in first run it prints the result out but on second run the result
is 'nil' again. I can run 1000 run the first 999 is correct but 1000th
run is nil again. what does realy cause this?
Huseyin P. (Guest)
on 2006-04-06 13:57
I found it, it was
query = query.split(/ /)
some reason when I change to
query = query.scan(/\w+/)
it worked HOWEVER
THIS TIME IT IGNORES MY PHARANTESIS, how can I scan so that it would
take the pharanthesis as another piece of string ?
thank you
This topic is locked and can not be replied to.