Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rowx.rb
Instance Method Summary collapse
Instance Method Details
#collate(pattern = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rowx.rb', line 9 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 |