summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2020-11-24 14:05:22 -0800
committerJeremy Evans <[email protected]>2021-03-06 13:56:16 -0800
commitbf40fe9fed19a5e22081b133661c0629988f1618 ()
tree0a24947c37be27b59e3fe84bd8e3a72711b9e907 /enumerator.c
parent13dc00534786057c6b934b7269dac49352959099 (diff)
Fix calling enumerator methods such as with_index on Enumerator::Chain
This previously raised a TypeError. Wrap the Enumerator::Chain in an Enumerator to work around the problem. Fixes [Bug #17216]
Notes: Merged: https://.com/ruby/ruby/pull/3811
-rw-r--r--enumerator.c30
1 files changed, 14 insertions, 16 deletions
@@ -517,27 +517,25 @@ static VALUE
lazy_to_enum_i(VALUE self, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn, int kw_splat);
VALUE
-rb_enumeratorize_with_size(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn)
{
- /* Similar effect as calling obj.to_enum, i.e. dising to either
- Kernel#to_enum vs Lazy#to_enum */
- if (RTEST(rb_obj_is_kind_of(obj, rb_cLazy)))
- return lazy_to_enum_i(obj, meth, argc, argv, size_fn, rb_keyword_given_p());
- else
- return enumerator_init(enumerator_allocate(rb_cEnumerator),
- obj, meth, argc, argv, size_fn, Qnil, rb_keyword_given_p());
}
VALUE
-rb_enumeratorize_with_size_kw(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn, int kw_splat)
{
- /* Similar effect as calling obj.to_enum, i.e. dising to either
- Kernel#to_enum vs Lazy#to_enum */
- if (RTEST(rb_obj_is_kind_of(obj, rb_cLazy)))
- return lazy_to_enum_i(obj, meth, argc, argv, size_fn, kw_splat);
- else
- return enumerator_init(enumerator_allocate(rb_cEnumerator),
- obj, meth, argc, argv, size_fn, Qnil, kw_splat);
}
static VALUE