From 615cff235faaf719d2f0cb83f99f0edb4e0991c2 Mon Sep 17 00:00:00 2001 From: burningTyger Date: Thu, 6 Oct 2011 00:01:43 +0200 Subject: [PATCH] enum.c method description tweaks --- enum.c | 41 +++++++++++++++++------------------------ 1 files changed, 17 insertions(+), 24 deletions(-) diff --git a/enum.c b/enum.c index 91ca407..5fe9938 100644 --- a/enum.c +++ b/enum.c @@ -129,11 +129,10 @@ count_all_i(VALUE i, VALUE memop, int argc, VALUE *argv) * enum.count(item) -> int * enum.count { |obj| block } -> int * - * Returns the number of items in enum, 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 enum, for which equals to item. If a block is - * given, counts the number of elements yielding a true value. + * Returns the number of items in enum if it responds to a #size call. + * Otherwise the items are counted through enumeration. If an argument is given + * the number of items in enum that are equal to item 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 @@ -539,10 +538,9 @@ inject_op_i(VALUE i, VALUE p, int argc, VALUE *argv) * return value for the method. * * If you do not explicitly specify an initial value for memo, - * 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 memo. * - * Examples: * * # Sum some numbers * (5..10).reduce(:+) #=> 45 @@ -658,13 +656,12 @@ group_by_i(VALUE i, VALUE hash, int argc, VALUE *argv) * 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 enum - * corresponding to the key. + * Returns a hash with keys that are block evaluation results and array values + * that are enum 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]} * */ @@ -837,7 +834,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * The current implementation of sort_by generates an * array of tuples containing the original collection element and the * mapped value. This makes sort_by fairly expensive when - * the keysets are simple + * the keysets are simple. * * require 'benchmark' * @@ -970,9 +967,9 @@ DEFINE_ENUMFUNCS(all) * Passes each element of the collection to the given block. The method * returns true if the block never returns * false or nil. If the block is not given, - * Ruby adds an implicit block of { |obj| obj } (that is - * all? will return true only if none of the - * collection members are false or nil.) + * Ruby adds an implicit block of { |obj| obj } which will return + * true only if none of the collection members are + * false or nil. * * %w{ant bear cat}.all? { |word| word.length >= 3 } #=> true * %w{ant bear cat}.all? { |word| word.length >= 4 } #=> false @@ -1005,10 +1002,9 @@ DEFINE_ENUMFUNCS(any) * Passes each element of the collection to the given block. The method * returns true if the block ever returns a value other * than false or nil. If the block is not - * given, Ruby adds an implicit block of { |obj| obj } (that - * is any? will return true if at least one - * of the collection members is not false or - * nil. + * given, Ruby adds an implicit block of { |obj| obj } that + * will return true if at least one of the collection members is + * not false or nil. * * %w{ant bear cat}.any? { |word| word.length >= 3 } #=> true * %w{ant bear cat}.any? { |word| word.length >= 4 } #=> true @@ -1552,8 +1548,8 @@ minmax_by_i(VALUE i, VALUE _memo, int argc, VALUE *argv) * enum.minmax_by { |obj| block } -> [min, max] * enum.minmax_by -> an_enumerator * - * Returns two elements array array containing the objects in - * enum that gives the minimum and maximum values respectively + * Returns a two element array containing the objects in + * enum that correspond to the minimum and maximum values respectively * from the given block. * * If no block is given, an enumerator is returned instead. @@ -1762,7 +1758,6 @@ each_slice_i(VALUE i, VALUE *memo, int argc, VALUE *argv) * Iterates the given block for each slice of elements. If no * block is given, returns an enumerator. * - * e.g.: * (1..10).each_slice(3) { |a| p a } * # outputs below * [1, 2, 3] @@ -1816,7 +1811,6 @@ each_cons_i(VALUE i, VALUE *memo, int argc, VALUE *argv) * Iterates the given block for each array of consecutive * elements. If no block is given, returns an enumerator. * - * e.g.: * (1..10).each_cons(3) { |a| p a } * # outputs below * [1, 2, 3] @@ -1862,7 +1856,6 @@ each_with_object_i(VALUE i, VALUE memo, int argc, VALUE *argv) * * 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.7.7