title: Split array into sub-arrays based on value
body: <p>I was looking for an Array equivalent <code>String#split</code> in Ruby Core, and was surprised to find that it did not exist. Is there a more elegant way than the following to split an array into sub-arrays based on a value?</p>
  
  <pre><code>class Array
    def split( split_on=nil )
      inject([[]]) do |a,v|
        a.tap{
          if block_given? ? yield(v) : v==split_on
            a &lt;&lt; []
          else
            a.last &lt;&lt; v
          end
        }
      end.tap{ |a| a.pop if a.last.empty? }
    end
  end
  
  p (1..9 ).to_a.split{ |i| i%3==0 },
    (1..10).to_a.split{ |i| i%3==0 }
  #=&gt; [[1, 2], [4, 5], [7, 8]]
  #=&gt; [[1, 2], [4, 5], [7, 8], [10]]
  </code></pre>
  
  <p><strong>Edit</strong>: For those interested, the "real-world" problem which sparked this request can be seen in <a href="https://stackoverflow.com/questions/4798976/nokogiri-need-to-turn-markup-partitioned-by-hr-into-divs/4801341#4801341">this answer</a>, where I've used @fd's answer below for the implementation.</p>