Project

General

Profile

Bug #5411 » 0001-enum.c-method-description-tweaks.patch

enum.c patch - bt (Bernd Homuth), 10/06/2011 07:07 AM

View differences:

enum.c
* enum.count(item) -> int
* enum.count { |obj| block } -> int
*
* Returns the number of items in <i>enum</i>, where #size is called
* if it responds to it, otherwise the items are counted through
* enumeration. If an argument is given, counts the number of items
* in <i>enum</i>, for which equals to <i>item</i>. If a block is
* given, counts the number of elements yielding a true value.
* Returns the number of items in <i>enum</i> if it responds to a #size call.
* Otherwise the items are counted through enumeration. If an argument is given
* the number of items in <i>enum</i> that are equal to <i>item</i> are counted.
* If a block is given, it counts the number of elements yielding a true value.
*
* ary = [1, 2, 4, 2]
* ary.count #=> 4
......
* return value for the method.
*
* If you do not explicitly specify an <i>initial</i> value for <i>memo</i>,
* then uses the first element of collection is used as the initial value
* then the first element of collection is used as the initial value
* of <i>memo</i>.
*
* Examples:
*
* # Sum some numbers
* (5..10).reduce(:+) #=> 45
......
* enum.group_by { |obj| block } -> a_hash
* enum.group_by -> an_enumerator
*
* Returns a hash, which keys are evaluated result from the
* block, and values are arrays of elements in <i>enum</i>
* corresponding to the key.
* Returns a hash with keys that are block evaluation results and array values
* that are <i>enum</i> items which correspond to the keys.
*
* If no block is given, an enumerator is returned instead.
*
* (1..6).group_by { |i| i%3 } #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
* (1..6).group_by { |i| i%3 } #=> {1=>[1, 4], 2=>[2, 5], 0=>[3, 6]}
*
*/
......
* The current implementation of <code>sort_by</code> generates an
* array of tuples containing the original collection element and the
* mapped value. This makes <code>sort_by</code> fairly expensive when
* the keysets are simple
* the keysets are simple.
*
* require 'benchmark'
*
......
* Passes each element of the collection to the given block. The method
* returns <code>true</code> if the block never returns
* <code>false</code> or <code>nil</code>. If the block is not given,
* Ruby adds an implicit block of <code>{ |obj| obj }</code> (that is
* <code>all?</code> will return <code>true</code> only if none of the
* collection members are <code>false</code> or <code>nil</code>.)
* Ruby adds an implicit block of <code>{ |obj| obj }</code> which will return
* <code>true</code> only if none of the collection members are
* <code>false</code> or <code>nil</code>.
*
* %w{ant bear cat}.all? { |word| word.length >= 3 } #=> true
* %w{ant bear cat}.all? { |word| word.length >= 4 } #=> false
......
* Passes each element of the collection to the given block. The method
* returns <code>true</code> if the block ever returns a value other
* than <code>false</code> or <code>nil</code>. If the block is not
* given, Ruby adds an implicit block of <code>{ |obj| obj }</code> (that
* is <code>any?</code> will return <code>true</code> if at least one
* of the collection members is not <code>false</code> or
* <code>nil</code>.
* given, Ruby adds an implicit block of <code>{ |obj| obj }</code> that
* will return <code>true</code> if at least one of the collection members is
* not <code>false</code> or <code>nil</code>.
*
* %w{ant bear cat}.any? { |word| word.length >= 3 } #=> true
* %w{ant bear cat}.any? { |word| word.length >= 4 } #=> true
......
* enum.minmax_by { |obj| block } -> [min, max]
* enum.minmax_by -> an_enumerator
*
* Returns two elements array array containing the objects in
* <i>enum</i> that gives the minimum and maximum values respectively
* Returns a two element array containing the objects in
* <i>enum</i> that correspond to the minimum and maximum values respectively
* from the given block.
*
* If no block is given, an enumerator is returned instead.
......
* Iterates the given block for each slice of <n> elements. If no
* block is given, returns an enumerator.
*
* e.g.:
* (1..10).each_slice(3) { |a| p a }
* # outputs below
* [1, 2, 3]
......
* Iterates the given block for each array of consecutive <n>
* elements. If no block is given, returns an enumerator.
*
* e.g.:
* (1..10).each_cons(3) { |a| p a }
* # outputs below
* [1, 2, 3]
......
*
* If no block is given, returns an enumerator.
*
* e.g.:
* evens = (1..10).each_with_object([]) { |i, a| a << i*2 }
* #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
*
(1-1/2)