From 28d1f6cdc48782247b6d39be0e1a794404da26f5 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 30 Aug 2019 17:04:25 +0900 Subject: `Array#(permutation|combination)` without block should return `self` --- mrbgems/mruby-array-ext/mrblib/array.rb | 14 +++++++------- mrbgems/mruby-array-ext/test/array.rb | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'mrbgems/mruby-array-ext') diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 1cd1eb643..fef78f83f 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -815,12 +815,11 @@ class Array # a.permutation(0).to_a #=> [[]] # one permutation of length 0 # a.permutation(4).to_a #=> [] # no permutations of length 4 def permutation(n=self.size, &block) - size = self.size return to_enum(:permutation, n) unless block - return if n > size + size = self.size if n == 0 - yield [] - else + yield [] + elsif n <= size i = 0 while i [] # no combinations of length 5 def combination(n, &block) - size = self.size return to_enum(:combination, n) unless block - return if n > size + size = self.size if n == 0 yield [] elsif n == 1 @@ -872,7 +871,7 @@ class Array yield [self[i]] i += 1 end - else + elsif n <= size i = 0 while i