summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-06-02 20:00:35 -0700
committerJeremy Evans <code@jeremyevans.net>2019-06-02 20:00:35 -0700
commit17af8bfce6508951edca8650155be5525a894f65 (patch)
treeaa76ef5e567dca3b56937f2cbf18a43576a34397 /enum.c
parentf48aad7ba22811dcd5e5be7af667ec49301ad7cd (diff)
Make size on an infinite each_slice enumerator return Infinity
Fixes [Bug #15889]
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index 609438b..56cef17 100644
--- a/enum.c
+++ b/enum.c
@@ -2527,10 +2527,15 @@ enum_each_slice_size(VALUE obj, VALUE args, VALUE eobj)
{
VALUE n, size;
long slice_size = NUM2LONG(RARRAY_AREF(args, 0));
+ ID infinite_p;
+ CONST_ID(infinite_p, "infinite?");
if (slice_size <= 0) rb_raise(rb_eArgError, "invalid slice size");
size = enum_size(obj, 0, 0);
if (size == Qnil) return Qnil;
+ if (RB_FLOAT_TYPE_P(size) && RTEST(rb_funcall(size, infinite_p, 0))) {
+ return size;
+ }
n = add_int(size, slice_size-1);
return div_int(n, slice_size);