From: Shawn Anderson Date: 2008-09-20T05:00:33+09:00 Subject: Re: Confused regarding text example ------=_Part_41775_17037297.1221854901390 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline class WordIndex def initialize @index = {} end def add_to_index(obj, *phrases) phrases.each do |phrase| phrase.scan(/\w[\w']+/) do |word| # extract each word word.downcase! @index[word] = [] if @index[word].nil? @index[word].push(obj) end end end def lookup(word) @index[word.downcase] end end phrases contains the phases/patterns to look for. |phrase| is replaced by each of the phrases to check for. the *phrases in the method signature says that it takes a variable number of arguments, you use those as an array of values. phrases.each do |phrase| # code end this piece of code defines a block aka closer that takes one argument. the each method on array will call this block for every item in the array as the argument to this block After that, I become a bit ocnfused. I know they are looking for the phrase in each of the words (.\w\w']+/) but how does that work? /\w[\w']+/ is a shorthand for writing Regexp.new("/\w[\w']+/") the scan method on a string will return an array of all the matches of that regexp: http://ruby-doc.org/core/classes/String.html#M000827 How is each string broken down into "words"? w hy is that done anyway (why not just find the pattern and move on?). The code appears to be adding obj to a hash based on the downcased version of each word in each phrase. Also, what is obj exactly (other than an object)? How is it being formed so it can be pushed into the stack? obj is just passed in, it could be anything, it could be the filename that these words were pulled from.. or whatever you would want to retrieve based on the words in the phrases associated with it. Finally, what does index[word] represent? I am guessing a hash... See above, you are right! @index = {} is shorthand for @index = Hash.new the same way @foo = [] is shorthand for @foo = Array.new Hope this helps. If I have made anything unclear please feel free to email me. ------=_Part_41775_17037297.1221854901390--