Skip to content

Instantly share code, notes, and snippets.

@korny
Created October 12, 2013 16:31
Show Gist options
  • Save korny/6951979 to your computer and use it in GitHub Desktop.
Save korny/6951979 to your computer and use it in GitHub Desktop.
Simplistic backport of Enumerable#slice_before from Ruby 1.9 to Ruby 1.8.
class Array
def slice_before
[].tap do |chunks|
each do |item|
chunks << [] if yield(item) || chunks.empty?
chunks.last << item
chunks
end
end
end
end
@korny
Copy link
Author

korny commented Oct 12, 2013

Here's the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment