[PATCH] Implement Array#permutation #131

mattdaw opened this Issue Dec 30, 2009 · 3 comments


None yet
2 participants

mattdaw commented Dec 30, 2009

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


marcandre commented Dec 30, 2009

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.


marcandre commented Dec 31, 2009

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).


mattdaw commented Dec 31, 2009

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