@@ -7213,68 +7213,41 @@ rb_ary_repeated_permutation_size(VALUE ary, VALUE args, VALUE eobj)
7213
7213
7214
7214
/*
7215
7215
* call-seq:
7216
- * array. repeated_permutation(n ) {|permutation| ... } -> self
7217
- * array. repeated_permutation(n ) -> new_enumerator
7216
+ * repeated_permutation(size ) {|permutation| ... } -> self
7217
+ * repeated_permutation(size ) -> new_enumerator
7218
7218
*
7219
- * Calls the block with each repeated permutation of length +n+ of the elements of +self+;
7220
- * each permutation is an +Array+;
7219
+ * With a block given, calls the block with each repeated permutation of length +size+
7220
+ * of the elements of +self+;
7221
+ * each permutation is an array;
7221
7222
* returns +self+. The order of the permutations is indeterminate.
7222
7223
*
7223
- * When a block and a positive Integer argument +n+ are given, calls the block with each
7224
- * +n+-tuple repeated permutation of the elements of +self+.
7225
- * The number of permutations is <tt>self.size**n</tt>.
7226
- *
7227
- * +n+ = 1:
7228
- *
7229
- * a = [0, 1, 2]
7230
- * a.repeated_permutation(1) {|permutation| p permutation }
7231
- *
7232
- * Output:
7233
- *
7234
- * [0]
7235
- * [1]
7236
- * [2]
7237
- *
7238
- * +n+ = 2:
7239
- *
7240
- * a.repeated_permutation(2) {|permutation| p permutation }
7224
+ * If a positive integer argument +size+ is given,
7225
+ * calls the block with each +size+-tuple repeated permutation of the elements of +self+.
7226
+ * The number of permutations is <tt>self.size**size</tt>.
7241
7227
*
7242
- * Output :
7228
+ * Examples :
7243
7229
*
7244
- * [0, 0]
7245
- * [0, 1]
7246
- * [0, 2]
7247
- * [1, 0]
7248
- * [1, 1]
7249
- * [1, 2]
7250
- * [2, 0]
7251
- * [2, 1]
7252
- * [2, 2]
7230
+ * - +size+ is 1:
7253
7231
*
7254
- * If +n+ is zero, calls the block once with an empty +Array+.
7232
+ * p = []
7233
+ * [0, 1, 2].repeated_permutation(1) {|permutation| p.push(permutation) }
7234
+ * p # => [[0], [1], [2]]
7255
7235
*
7256
- * If +n + is negative, does not call the block :
7236
+ * - +size + is 2 :
7257
7237
*
7258
- * a.repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
7238
+ * p = []
7239
+ * [0, 1, 2].repeated_permutation(2) {|permutation| p.push(permutation) }
7240
+ * p # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
7259
7241
*
7260
- * Returns a new Enumerator if no block given:
7242
+ * If +size+ is zero, calls the block once with an empty array.
7261
7243
*
7262
- * a = [0, 1, 2]
7263
- * a.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
7244
+ * If +size+ is negative, does not call the block:
7264
7245
*
7265
- * Using Enumerators, it's convenient to show the permutations and counts
7266
- * for some values of +n+:
7246
+ * [0, 1, 2].repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
7267
7247
*
7268
- * e = a.repeated_permutation(0)
7269
- * e.size # => 1
7270
- * e.to_a # => [[]]
7271
- * e = a.repeated_permutation(1)
7272
- * e.size # => 3
7273
- * e.to_a # => [[0], [1], [2]]
7274
- * e = a.repeated_permutation(2)
7275
- * e.size # => 9
7276
- * e.to_a # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
7248
+ * With no block given, returns a new Enumerator.
7277
7249
*
7250
+ * Related: see {Methods for Combining}[rdoc-ref:Array@Methods+for+Combining].
7278
7251
*/
7279
7252
static VALUE
7280
7253
rb_ary_repeated_permutation (VALUE ary , VALUE num )
0 commit comments