Skip to content

Commit c519476

Browse files
[DOC] Tweaks for Array#repeated_permutation (#11873)
1 parent a9fb0a2 commit c519476

File tree

1 file changed

+22
-49
lines changed

1 file changed

+22
-49
lines changed

array.c

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7213,68 +7213,41 @@ rb_ary_repeated_permutation_size(VALUE ary, VALUE args, VALUE eobj)
72137213

72147214
/*
72157215
* 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
72187218
*
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;
72217222
* returns +self+. The order of the permutations is indeterminate.
72227223
*
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>.
72417227
*
7242-
* Output:
7228+
* Examples:
72437229
*
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:
72537231
*
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]]
72557235
*
7256-
* If +n+ is negative, does not call the block:
7236+
* - +size+ is 2:
72577237
*
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]]
72597241
*
7260-
* Returns a new Enumerator if no block given:
7242+
* If +size+ is zero, calls the block once with an empty array.
72617243
*
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:
72647245
*
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' }
72677247
*
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.
72777249
*
7250+
* Related: see {Methods for Combining}[rdoc-ref:Array@Methods+for+Combining].
72787251
*/
72797252
static VALUE
72807253
rb_ary_repeated_permutation(VALUE ary, VALUE num)

0 commit comments

Comments
 (0)