Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created October 6, 2009 16:39
Show Gist options
  • Select an option

  • Save KirinDave/203180 to your computer and use it in GitHub Desktop.

Select an option

Save KirinDave/203180 to your computer and use it in GitHub Desktop.
class Array
def multisplit(wordlist, &block)
result = wordlist.inject([[],[]]) do |memo,word|
bigaccum, smallaccum = memo
if block.call(word)
[bigaccum.push(smallaccum.compact),[]]
else
[bigaccum,smallaccum.push(word)]
end
end
return result[0].compact.push(result[1]).compact
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment