T
Thibaut Barrère
Hi
could more advanced rubyists review this code (it's already a mixture
of several things I've seen, but a review cannot hurt!) ?
module Enumerable
def split(pattern)
inject([]) do |memo,obj|
memo.push [] if obj =~ pattern
memo.last << obj
memo
end
end
end
Typical usage: split an array like ['Application starting...','I do
work','Application starting...','I still do work'] into [['Application
starting...','I do work'],['Application starting...','I still do
work']].
(or is there something built-in to handle that?)
thanks!
Thibaut
could more advanced rubyists review this code (it's already a mixture
of several things I've seen, but a review cannot hurt!) ?
module Enumerable
def split(pattern)
inject([]) do |memo,obj|
memo.push [] if obj =~ pattern
memo.last << obj
memo
end
end
end
Typical usage: split an array like ['Application starting...','I do
work','Application starting...','I still do work'] into [['Application
starting...','I do work'],['Application starting...','I still do
work']].
(or is there something built-in to handle that?)
thanks!
Thibaut