summaryrefslogtreecommitdiff
path: root/hash.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 /hash.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 'hash.c')
-rw-r--r--hash.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index d2ca057..3a49987 100644
--- a/hash.c
+++ b/hash.c
@@ -4690,6 +4690,8 @@ Init_Hash(void)
rb_define_method(rb_cHash, "keep_if", rb_hash_keep_if, 0);
rb_define_method(rb_cHash, "select", rb_hash_select, 0);
rb_define_method(rb_cHash, "select!", rb_hash_select_bang, 0);
+ rb_define_method(rb_cHash, "filter", rb_hash_select, 0);
+ rb_define_method(rb_cHash, "filter!", rb_hash_select_bang, 0);
rb_define_method(rb_cHash, "reject", rb_hash_reject, 0);
rb_define_method(rb_cHash, "reject!", rb_hash_reject_bang, 0);
rb_define_method(rb_cHash, "slice", rb_hash_slice, -1);
@@ -4752,6 +4754,8 @@ Init_Hash(void)
rb_define_singleton_method(envtbl, "reject!", env_reject_bang, 0);
rb_define_singleton_method(envtbl, "select", env_select, 0);
rb_define_singleton_method(envtbl, "select!", env_select_bang, 0);
+ rb_define_singleton_method(envtbl, "filter", env_select, 0);
+ rb_define_singleton_method(envtbl, "filter!", env_select_bang, 0);
rb_define_singleton_method(envtbl, "shift", env_shift, 0);
rb_define_singleton_method(envtbl, "invert", env_invert, 0);
rb_define_singleton_method(envtbl, "replace", env_replace, 1);