#--
# Credit goes to Thibaut Barrère.
#++

module Enumerable

  # Split an array on matching pattern.
  #
  # ['a1','b1','a2','b2'].divide(/^a/)
  # => [['a1,'b1'],['a2','b2']]

  def divide(pattern)
    inject([]) do |memo,obj|
      memo.push [] if pattern === obj
      memo.last << obj
      memo
    end
  end

end
