Q:

confused as to the behavior of this ruby fragment

Sorry to ask this but I really need to get this done. I'd like to be able to pass in a string and strip out the stop_words. I have the following:
class Query
  def self.normalize term
    stop_words=["a","big","array"]
    term.downcase!
    legit=[]
    if !stop_words.include?(term)
      legit << term
    end
    return legit
  end

  def self.check_parts term
    term_parts=term.split(' ')
    tmp_part=[]
    term_parts.each do |part|
      t=self.normalize part
      tmp_part << t
    end  
    return tmp_part  
  end
end

I would think that this would return only terms that are not in the stop_words list but I'm getting back either an empty array or an array of the terms passed in. Like this:
ruby-1.9.2-p290 :146 > Query.check_parts "here Is my Char"
 => [[], [], [], ["char"]] 
ruby-1.9.2-p290 :147 >

What am I doing wrong?
thx in advance

A:

If you just want to filter out the terms and get an array of downcased words, it is simple.
module Query
  StopWords = %w[a big array]
  def self.check_parts string; string.downcase.split(/\s+/) - StopWords end
end

Query.check_parts("here Is my Char") # => ["here", "is", "my", "char"]

