aboutsummaryrefslogtreecommitdiffstats
path: root/enumerator.c
diff options
context:
space:
mode:
authorAkinori MUSHA <knu@idaemons.org>2022-12-21 19:13:15 +0900
committerAkinori MUSHA <knu@idaemons.org>2022-12-21 19:13:15 +0900
commitcc4c28ec2efa71b1c8afb4ce11409ad7b5ca1c95 (patch)
treeb1ff353f37906ebda486d474d817958ddb2019a5 /enumerator.c
parent308ccbaeb2c1c0e78d59c0411ddbeede8d2324f0 (diff)
downloadruby-cc4c28ec2efa71b1c8afb4ce11409ad7b5ca1c95.tar.gz
Make Enumerartor.product return nil when called with a block
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/enumerator.c b/enumerator.c
index eb402804eb..f6b3aae1f7 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -3725,6 +3725,7 @@ enum_product_inspect(VALUE obj)
/*
* call-seq:
* Enumerator.product(*enums) -> enumerator
+ * Enumerator.product(*enums) { |elts| ... } -> enumerator
*
* Generates a new enumerator object that generates a Cartesian
* product of given enumerable objects. This is equivalent to
@@ -3733,6 +3734,9 @@ enum_product_inspect(VALUE obj)
* e = Enumerator.product(1..3, [4, 5])
* e.to_a #=> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]
* e.size #=> 6
+ *
+ * When a block is given, calls the block with each N-element array
+ * generated and returns +nil+.
*/
static VALUE
enumerator_s_product(int argc, VALUE *argv, VALUE klass)
@@ -3747,9 +3751,12 @@ enumerator_s_product(int argc, VALUE *argv, VALUE klass)
VALUE obj = enum_product_initialize(argc, argv, enum_product_allocate(rb_cEnumProduct));
- if (NIL_P(block)) return obj;
+ if (!NIL_P(block)) {
+ enum_product_run(obj, block);
+ return Qnil;
+ }
- return enum_product_run(obj, block);
+ return obj;
}
/*