Skip to content

Instantly share code, notes, and snippets.

@korny
Created October 12, 2013 16:31
Show Gist options
  • Select an option

  • Save korny/6951979 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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