Forum: Ruby on Rails Strench Error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8aafedcf44e49905528db92dce034879?d=identicon&s=25 Huseyin Polat (hpolat)
on 2006-04-06 11:49
I am new with ruby but something fishy with the array.
if I type
q=aa
puts INV_FILE_HASH[q]   # where INV_FILE_HASH is my hash function
I GET THE RESULT PERFECTLY HOWEVER,
query is user input and couldbe 'aa' or 'aa aa'
query = query.split(/ /)
 query.each { |q|
  if (q == 'and')
    OP.push('and')
  elsif (q == 'or')
    OP.push('or')
  else
    # q=aa at this point which is correct
    puts INV_FILE_HASH[q]    # prints out nil instead of values
  end
}

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?
8aafedcf44e49905528db92dce034879?d=identicon&s=25 Huseyin Polat (hpolat)
on 2006-04-06 11: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.