2008/2/12 said:
oops i took the easy way and replied. sorry.
Thanks for the help/explanation. I was hoping there was a shorter/
more efficient way than iterating maybe a nested hash of some sort.
Nested Hashes would only help if you would know beforehand according
to which criteria you want to split up your strings. If you are doing
it on word basis you could do this
require 'set'
word_index = Hash.new {|h,k| h[k] = Set.new}
x.each_key {|k| k.downcase.scan(/\w+/) {|wd| word_index[wd] << k}}
Note though that you have to update word_index whenever x changes.
Well, there are indexing structures optimized for text retrieval (your
favorite search engine is using those). However, I have no idea
whether there are libs that implement those in Ruby. You could try to
check RAA at
http://raa.ruby-lang.org/ for such libs.
Kind regards
robert