Skip to content


Subversion checkout URL

You can clone with
Download ZIP


[PATCH] Implement Array#permutation #131

mattdaw opened this Issue · 3 comments

2 participants


Here's a conversion of MRI 1.8.7's Array#permutation.

None of spec/ruby/core/array/permutation_spec.rb was passing before because there was no implementation of this method. Here's the clean test run now:

$ bin/mspec spec/ruby/core/array/permutation_spec.rb
rubinius 1.0.0-rc1 (1.8.7 a609348 2009-11-25 JI) [x86_64-apple-darwin10.2.0]

Finished in 0.008948 seconds

1 file, 10 examples, 30 expectations, 0 failures, 0 errors


Looks like I overlooked this method when I ported to 1.8.7.
I see a potential bug with this, so I'll go over the code more attentively, and commit it (after updating the rubyspec for that potential failure too).
I'll adapt the code to my backports gem too.


I kept the algorithm as is, I simply made the code simpler. Also fixed the potential bug whereby the size of the array was cached in the enumerator (see rubyspec).


Cool, the yield values_at(*p) is a good trick.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.