From a5e1d549b508806b2fd14100683f504c7825a138 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 1 Jun 2023 13:33:59 +0900 Subject: [PATCH] [DOC] Mention the edge case of `any?`/`all?` --- array.c | 6 ++++++ enum.c | 7 ++++++- hash.c | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/array.c b/array.c index 72c796728d..a99fd9c73d 100644 --- a/array.c +++ b/array.c @@ -7768,6 +7768,9 @@ rb_ary_drop_while(VALUE ary) * * Returns +true+ if any element of +self+ meets a given criterion. * + * If +self+ has no element, returns +false+ and argument or block + * are not used. + * * With no block given and no argument, returns +true+ if +self+ has any truthy element, * +false+ otherwise: * @@ -7829,6 +7832,9 @@ rb_ary_any_p(int argc, VALUE *argv, VALUE ary) * * Returns +true+ if all elements of +self+ meet a given criterion. * + * If +self+ has no element, returns +true+ and argument or block + * are not used. + * * With no block given and no argument, returns +true+ if +self+ contains only truthy elements, * +false+ otherwise: * diff --git a/enum.c b/enum.c index 490b5e4fc8..6fc2fc9b17 100644 --- a/enum.c +++ b/enum.c @@ -1757,6 +1757,9 @@ DEFINE_ENUMFUNCS(all) * * Returns whether every element meets a given criterion. * + * If +self+ has no element, returns +true+ and argument or block + * are not used. + * * With no argument and no block, * returns whether every element is truthy: * @@ -1818,6 +1821,9 @@ DEFINE_ENUMFUNCS(any) * * Returns whether any element meets a given criterion. * + * If +self+ has no element, returns +false+ and argument or block + * are not used. + * * With no argument and no block, * returns whether any element is truthy: * @@ -1848,7 +1854,6 @@ DEFINE_ENUMFUNCS(any) * {foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 1 } # => true * {foo: 0, bar: 1, baz: 2}.any? {|key, value| value < 0 } # => false * - * * Related: #all?, #none?, #one?. */ diff --git a/hash.c b/hash.c index bb356725b2..0aab4443df 100644 --- a/hash.c +++ b/hash.c @@ -4432,6 +4432,9 @@ any_p_i_pattern(VALUE key, VALUE value, VALUE arg) * Returns +true+ if any element satisfies a given criterion; * +false+ otherwise. * + * If +self+ has no element, returns +false+ and argument or block + * are not used. + * * With no argument and no block, * returns +true+ if +self+ is non-empty; +false+ if empty. * @@ -4450,6 +4453,8 @@ any_p_i_pattern(VALUE key, VALUE value, VALUE arg) * h = {foo: 0, bar: 1, baz: 2} * h.any? {|key, value| value < 3 } # => true * h.any? {|key, value| value > 3 } # => false + * + * Related: Enumerable#any? */ static VALUE