title: Ruby inject condition
body: <p>I have an array filled with hashes. The data structure looks like this:</p>
  
  <pre><code>students = [
    {
      "first_name" =&gt; "James",
      "last_name" =&gt; "Sullivan",
      "age" =&gt; 20,
      "study_results" =&gt; {"CAR" =&gt; 1, "PR1" =&gt; 1, "MA1" =&gt; 1, "BEN" =&gt; 2, "SDP" =&gt; nil}
    }
  ]
  </code></pre>
  
  <p>I want to find students with the mark <code>1</code> from at least two subjects.</p>
  
  <p>I tried to convert the hash with marks into an array and then use the <code>inject</code> method to count the number of <code>1</code> and find out if the number is <code>&gt; 1</code>:</p>
  
  <pre><code>students.select{|student
    (
      (student["study_results"].to_a)
      .inject(0){|sum, x| sum += 1 if x.include?(1)}
    ) &gt; 1
  }
  </code></pre>
  
  <p>Is there any way to put a condition into the method, or should I find a different way to solve it?</p>