# File lib/rubyful_soup.rb, line 159
  def PageElement.matches(chunk, how_to_match)
    #puts "Seeing if #{chunk.class} #{chunk} matches #{how_to_match.class} #{how_to_match}."
    #
    # If given a list of items, return true if the list contains a
    # text element that matches.
    if chunk.is_a? Array      
      chunk.each do |tag| 
        return true if tag.is_a? NavigableString and matches(tag, how_to_match)
      end
      return false
    elsif how_to_match.is_a? Proc
      return how_to_match.call(chunk)
    elsif chunk.is_a? Tag
      #Custom match methods take the tag as an argument, but all other
      #ways of matching match the tag name as a string
      chunk = chunk.name
    end

    #At this point we know that chunk is a string
    unless chunk.is_a? String
      chunk = chunk.to_s
    end
    if how_to_match.is_a? Regexp
      return how_to_match.match(chunk) != nil
    elsif how_to_match.is_a? Array
      return how_to_match.find {|x| x == chunk} != nil
    elsif how_to_match.is_a? Hash
      return how_to_match[chunk] != nil
    else
      #It's just a string
      return how_to_match.to_s == chunk
    end
  end