Created
July 11, 2010 06:23
-
-
Save igrep/471336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -wKu | |
# vim: set fileencoding=utf-8 : | |
=begin | |
return the results of both Enumerable#take and Enumerable#drop | |
=end | |
module Enumerable | |
def split_between val | |
first = true | |
first_ary = [] | |
second_ary = [] | |
self.each{|e| | |
if first | |
first_ary << e | |
first = false if e == val | |
else | |
second_ary << e | |
end | |
} | |
[first_ary, second_ary] | |
end | |
def split_between_if &block | |
first = true | |
first_ary = [] | |
second_ary = [] | |
self.each{|e| | |
if first | |
if yield(e) | |
first_ary << e | |
else | |
first = false | |
second_ary << e | |
end | |
else | |
second_ary << e | |
end | |
} | |
[first_ary, second_ary] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment