From 074bbe891084753c119f525e5c0ab533dd2196da Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 15 Aug 2025 23:06:26 +0900 Subject: [PATCH] mruby-array-ext: improve documentation for repeated combination/permutation The comments for `Array#repeated_combination` and `Array#repeated_permutation` were too concise. This commit expands them to be more descriptive and provides better examples. Co-authored-by: Gemini --- mrbgems/mruby-array-ext/mrblib/array.rb | 38 +++++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 9639c0e7a..9098a4056 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -646,10 +646,23 @@ class Array ## # call-seq: - # ary.repeated_combination(n) { |combination| ... } -> self - # ary.repeated_combination(n) -> enumerator + # ary.repeated_combination(n) { |combination| ... } -> ary + # ary.repeated_combination(n) -> Enumerator # - # A `combination` method that contains the same elements. + # When invoked with a block, yields all length `n` combinations of elements + # from the array, with replacement, and then returns the array itself. + # + # This means that, unlike `combination`, elements can be chosen more than once. + # + # The implementation makes no guarantees about the order in which the + # combinations are yielded. + # + # If no block is given, an Enumerator is returned instead. + # + # Examples: + # + # a = [1, 2, 3] + # a.repeated_combination(2).to_a #=> [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]] def repeated_combination(n, &block) raise TypeError, "no implicit conversion into Integer" unless 0 <=> n return to_enum(:repeated_combination, n) unless block @@ -658,10 +671,23 @@ class Array ## # call-seq: - # ary.repeated_permutation(n) { |permutation| ... } -> self - # ary.repeated_permutation(n) -> enumerator + # ary.repeated_permutation(n) { |permutation| ... } -> ary + # ary.repeated_permutation(n) -> Enumerator # - # A `permutation` method that contains the same elements. + # When invoked with a block, yields all length `n` permutations of elements + # from the array, with replacement, and then returns the array itself. + # + # This means that, unlike `permutation`, elements can be chosen more than once. + # + # The implementation makes no guarantees about the order in which the + # permutations are yielded. + # + # If no block is given, an Enumerator is returned instead. + # + # Examples: + # + # a = [1, 2] + # a.repeated_permutation(2).to_a #=> [[1,1],[1,2],[2,1],[2,2]] def repeated_permutation(n, &block) n = n.__to_int raise TypeError, "no implicit conversion into Integer" unless 0 <=> n