From 14c05517a9951a871967be1b13e8c306f386974e Mon Sep 17 00:00:00 2001 From: Jeff Saracco Date: Wed, 22 Aug 2012 19:52:25 -0400 Subject: [PATCH 1/3] update documentation for select and reject --- array.c | 10 +++++----- enum.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/array.c b/array.c index 524553a11918a1..c3b6e7027f8fab 100644 --- a/array.c +++ b/array.c @@ -2408,13 +2408,13 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary) * ary.select { |item| block } -> new_ary * ary.select -> Enumerator * - * Invokes the given block passing in successive elements from +self+, - * returning an array containing those elements for which the block returns - * a +true+ value. + * Returns a new array containing all elements of ary + * for which block does not return false + * (see also Enumerable#select). * - * See also Enumerable#select. + * If no block is given, an enumerator is returned instead. * - * If no block is given, an Enumerator is returned instead. + * [1,2,3,4,5].select { |num| num.even? } #=> [2, 4] * * a = %w{ a b c d e f } * a.select { |v| v =~ /[aeiou]/ } #=> ["a", "e"] diff --git a/enum.c b/enum.c index a24b3d2692cbbb..20b7a8eebe91c0 100644 --- a/enum.c +++ b/enum.c @@ -311,15 +311,17 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) * enum.find_all -> an_enumerator * enum.select -> an_enumerator * - * Returns an array containing all elements of enum for which - * block is not false (see also - * Enumerable#reject). + * Returns an array containing all elements of enum + * for which block does not return false + * (see also Enumerable#reject). * * If no block is given, an enumerator is returned instead. * * * (1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9] * + * [1,2,3,4,5].select { |num| num.even? } #=> [2, 4] + * */ static VALUE @@ -352,12 +354,14 @@ reject_i(VALUE i, VALUE ary, int argc, VALUE *argv) * enum.reject -> an_enumerator * * Returns an array for all elements of enum for which - * block is false (see also Enumerable#find_all). + * block returns false (see also Enumerable#find_all). * * If no block is given, an enumerator is returned instead. * * (1..10).reject { |i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10] * + * [1, 2, 3, 4, 5].reject { |num| num.even? } #=> [1, 3, 5] + * */ static VALUE From 2c1ceca4a184c63aad63af40b7ffb20dd77ba0e1 Mon Sep 17 00:00:00 2001 From: Jeff Saracco Date: Sat, 25 Aug 2012 11:04:18 -0400 Subject: [PATCH 2/3] make select and reject wording consistent returns true instead of `does not return false` --- array.c | 2 +- enum.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/array.c b/array.c index c3b6e7027f8fab..3eef1da17cef62 100644 --- a/array.c +++ b/array.c @@ -2409,7 +2409,7 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary) * ary.select -> Enumerator * * Returns a new array containing all elements of ary - * for which block does not return false + * for which block returns true. * (see also Enumerable#select). * * If no block is given, an enumerator is returned instead. diff --git a/enum.c b/enum.c index 20b7a8eebe91c0..c31376cfc466fc 100644 --- a/enum.c +++ b/enum.c @@ -312,7 +312,7 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) * enum.select -> an_enumerator * * Returns an array containing all elements of enum - * for which block does not return false + * for which block returns true. * (see also Enumerable#reject). * * If no block is given, an enumerator is returned instead. From af76190cf83f024ee15c23bb40db5201f4d12928 Mon Sep 17 00:00:00 2001 From: Jeff Saracco Date: Sat, 25 Aug 2012 11:23:38 -0400 Subject: [PATCH 3/3] select 'returns a true value' --- array.c | 2 +- enum.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/array.c b/array.c index 3eef1da17cef62..15db69b2941ca4 100644 --- a/array.c +++ b/array.c @@ -2409,7 +2409,7 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary) * ary.select -> Enumerator * * Returns a new array containing all elements of ary - * for which block returns true. + * for which block returns a true value. * (see also Enumerable#select). * * If no block is given, an enumerator is returned instead. diff --git a/enum.c b/enum.c index c31376cfc466fc..6d91687cd56f3f 100644 --- a/enum.c +++ b/enum.c @@ -312,7 +312,7 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) * enum.select -> an_enumerator * * Returns an array containing all elements of enum - * for which block returns true. + * for which block returns a true value. * (see also Enumerable#reject). * * If no block is given, an enumerator is returned instead.