module ArrayCollate
for an example of ArrayCollate
see www.jamesrobertson.eu/snippets/2014/jun/08/collating-items-in-an-array.html
Public Instance Methods
collate(pattern=nil) { |x| ... }
click to toggle source
# File lib/rowx.rb, line 16 def collate(pattern=nil) a = self.inject([[]]) do |r,x| if block_given? then yield(x) ? r << [x] : r[-1] << x else x =~ pattern ? r << [x] : r[-1] << x end # block r end a.shift if a.first.empty? a end