Taking the code from this other blog ... It's pretty elegant Ruby!
I won't waste your time repeating what the guy wrote in his blog - you're welcome to go read it. I just felt that I should help spread a little this elegant implementation of the standard permutation algorithm, fixing a small bug within it in the process. If, like me, you have issues understanding how to use this, well - you have to use this function and call a block of code on it. It runs the block of code on each permutation it finds.
Author Aldric Giacomoni