summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-25 13:52:07 (GMT)
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-25 13:52:07 (GMT)
commitb1a8c64483b5ba5e4a391aa68234e7bde6355034 (patch)
treefc7dc594e220ba737a0138666eed8841b55ab243 /enum.c
parentd1ea2f9d8f10ca728d178de92a26668c64f4aff8 (diff)
Add a new #filter alias for #select
* In Enumerable, Enumerator::Lazy, Array, Hash and Set [Feature #13784] [ruby-core:82285] * Share specs for the various #select#select! methods and reuse them for #filter/#filter!. * Add corresponding filter tests for select tests. * Update NEWS. [Fix GH-1824] From: Alexander Patrick <adp90@case.edu> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index 0df4461..b9b9ca7 100644
--- a/enum.c
+++ b/enum.c
@@ -388,8 +388,10 @@ enum_size_over_p(VALUE obj, long n)
* call-seq:
* enum.find_all { |obj| block } -> array
* enum.select { |obj| block } -> array
+ * enum.filter { |obj| block } -> array
* enum.find_all -> an_enumerator
* enum.select -> an_enumerator
+ * enum.filter -> an_enumerator
*
* Returns an array containing all elements of +enum+
* for which the given +block+ returns a true value.
@@ -401,6 +403,8 @@ enum_size_over_p(VALUE obj, long n)
*
* [1,2,3,4,5].select { |num| num.even? } #=> [2, 4]
*
+ * [:foo, :bar].filter { |x| x == :foo } #=> [:foo]
+ *
* See also Enumerable#reject.
*/
@@ -3994,6 +3998,7 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable, "find_index", enum_find_index, -1);
rb_define_method(rb_mEnumerable, "find_all", enum_find_all, 0);
rb_define_method(rb_mEnumerable, "select", enum_find_all, 0);
+ rb_define_method(rb_mEnumerable, "filter", enum_find_all, 0);
rb_define_method(rb_mEnumerable, "reject", enum_reject, 0);
rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
rb_define_method(rb_mEnumerable, "map", enum_collect, 0);