Permalink
Browse files

implement Env#keep_if

  • Loading branch information...
1 parent 2839b68 commit b76ccffe3d12b0469f4f8929f3c3d40d9db848a2 @Watson1978 Watson1978 committed Jun 21, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −0 env.c
  2. +0 −4 spec/frozen/tags/macruby/core/env/keep_if_tags.txt
View
9 env.c
@@ -373,6 +373,14 @@ env_select_bang(VALUE ehash, SEL sel)
}
static VALUE
+env_keep_if(VALUE ehash, SEL sel)
+{
+ RETURN_ENUMERATOR(ehash, 0, 0);
+ env_select_bang(ehash, 0);
+ return envtbl;
+}
+
+static VALUE
rb_env_clear_imp(VALUE rcv, SEL sel)
{
VALUE keys = env_keys(Qnil, 0); /* rb_secure(4); */
@@ -731,6 +739,7 @@ Init_ENV(void)
rb_objc_define_method(klass, "each_value", env_each_value, 0);
rb_objc_define_method(klass, "delete", env_delete_m, 1);
rb_objc_define_method(klass, "delete_if", env_delete_if, 0);
+ rb_objc_define_method(klass, "keep_if", env_keep_if, 0);
rb_objc_define_method(klass, "clear", rb_env_clear_imp, 0);
rb_objc_define_method(klass, "reject", env_reject, 0);
rb_objc_define_method(klass, "reject!", env_reject_bang, 0);
@@ -1,4 +0,0 @@
-fails:ENV.keep_if deletes pairs if the block returns false
-fails:ENV.keep_if returns ENV even if nothing deleted
-fails:ENV.keep_if returns an Enumerator if no block given
-fails:ENV.keep_if deletes pairs through enumerator

0 comments on commit b76ccff

Please sign in to comment.