From: Arun Kumar Date: 2009-04-29T21:37:17+09:00 Subject: Re: Random Access using IO#pos in code blocks --000e0cd3beb2dd78590468b0d6f6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > > unless freq.has_key?(word) > > freq[word] = [1,f.pos,file_name] # freq is a hash, that > > stores an array containing index, position of word (THE PROBLEM).. > > else > > freq[word].to_a[0] += 1 > > freq[word].to_a<< f.pos << file_name > > end > > BTW, you can replace all that by: > > freq[word] ||= [0] > freq[word][0] += 1 > freq[word] << f.pos << file_name > > I've tried doing it but since 'freq' is a hash it gives the following error: preprocessor.rb:32:in `calc_frequency_word_list': undefined method `[]=' for 0:Fixnum (NoMethodError) from copy of preprocessor.rb:25:in `scan' from copy of preprocessor.rb:25:in `calc_frequency_word_list' from copy of preprocessor.rb:23:in `each' from copy of preprocessor.rb:23:in `calc_frequency_word_list' from copy of preprocessor.rb:61 --000e0cd3beb2dd78590468b0d6f6--