[DOC] Tweaks for Array#take_while (#11930)

This commit is contained in:
Burdette Lamar 2024-10-22 11:36:12 -05:00 committed by GitHub
parent c837ae85d8
commit 9cbf2f5fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-10-22 16:36:32 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>

20
array.c
View File

@ -7509,25 +7509,23 @@ rb_ary_take(VALUE obj, VALUE n)
/*
* call-seq:
* array.take_while {|element| ... } -> new_array
* array.take_while -> new_enumerator
*
* Returns a new +Array+ containing zero or more leading elements of +self+;
* does not modify +self+.
* take_while {|element| ... } -> new_array
* take_while -> new_enumerator
*
* With a block given, calls the block with each successive element of +self+;
* stops if the block returns +false+ or +nil+;
* returns a new +Array+ containing those elements for which the block returned a truthy value:
* stops iterating if the block returns +false+ or +nil+;
* returns a new array containing those elements for which the block returned a truthy value:
*
* a = [0, 1, 2, 3, 4, 5]
* a.take_while {|element| element < 3 } # => [0, 1, 2]
* a.take_while {|element| true } # => [0, 1, 2, 3, 4, 5]
* a # => [0, 1, 2, 3, 4, 5]
* a.take_while {|element| true } # => [0, 1, 2, 3, 4, 5]
* a.take_while {|element| false } # => []
*
* With no block given, returns a new Enumerator:
* With no block given, returns a new Enumerator.
*
* [0, 1].take_while # => #<Enumerator: [0, 1]:take_while>
* Does not modify +self+.
*
* Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
*/
static VALUE