Split a Ruby Enumerable into chunks
Now and again I've had a need to split an array of strings into chunks divided by certain boundary patterns. Kind of like String.split, but for an array, and with multiple boundary patterns. The problem is something akin to splitting the different sections of a MIME multipart message.
In the latest instance, I wrestled with Ruby's takewhile and dropwhile for a bit, before giving in and kludging together an ugly state machine solution, which I shipped. However, I wasn't happy with it, so I went back and built a better solution.