title: Ruby Checking if string contains substring
body: <p>I have many log files, each contains a line like this one:</p>
  
  <pre><code>THIS LINE IS DIFFERENT CASE_WINDOWS_TEST_00 PASSED
  </code></pre>
  
  <p>I'm searching if line contains "_XXX_TEST_" string. I created a hash:</p>
  
  <pre><code>@@groups = {
      "_LINUX_TEST_" =&gt; "Linux_tests",
      "_WINDOWS_TEST_" =&gt; "Windows_tests"
  }
  </code></pre>
  
  <p>To check if the line contains a substring (a key from @@groups) I implemented method get_group_name which returns a value from @@groups.</p>
  
  <pre><code>def get_group_name(searchLine)
      @@groups.keys.each do |i| 
          if searchLine.include? i
              return @@groups[i]
          end
      end
  end
  </code></pre>
  
  <p>It works fine, returns proper values. I use this method in another method that iterates through log file.</p>
  
  <pre><code>def get_group_name_from_file(fileName)
      # fileName - filename or path to the file.txt
      file = File.open(fileName)
      while (line = file.gets)
          found = get_group_name(line)
          if found 
              return found
          end
      end
  end
  </code></pre>
  
  <p>And here is the problem. Method get_group_name_from_file returns list of keys from @@groups hash instead of one string (a value from that hash).</p>