# File lib/facet/array/permute.rb, line 18 def permute(prefixed=[]) if (length < 2) # there are no elements left to permute yield(prefixed + self) else # recursively permute the remaining elements each_with_index do |e, i| (self[0,i]+self[(i+1)..-1]).permute(prefixed+[e]) { |a| yield a } end end end