Skip to content

Commit

Permalink
implement Env#select!
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jun 21, 2012
1 parent 58f237c commit 2839b68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 26 additions & 0 deletions env.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ env_select(VALUE ehash, SEL sel)
return result;
}

static VALUE
env_select_bang(VALUE ehash, SEL sel)
{
volatile VALUE keys;
long i;
int del = 0;

RETURN_ENUMERATOR(ehash, 0, 0);
keys = env_keys(Qnil, 0); /* rb_secure(4); */
for (i=0; i<RARRAY_LEN(keys); i++) {
VALUE val = rb_f_getenv(Qnil, 0, RARRAY_AT(keys, i));
if (!NIL_P(val)) {
if (!RTEST(rb_yield_values(2, RARRAY_AT(keys, i), val))) {
rb_obj_untaint(RARRAY_AT(keys, i));
env_delete(Qnil, RARRAY_PTR(keys)[i]);
del++;
}
}
}
if (del == 0) {
return Qnil;
}
return envtbl;
}

static VALUE
rb_env_clear_imp(VALUE rcv, SEL sel)
{
Expand Down Expand Up @@ -710,6 +735,7 @@ Init_ENV(void)
rb_objc_define_method(klass, "reject", env_reject, 0);
rb_objc_define_method(klass, "reject!", env_reject_bang, 0);
rb_objc_define_method(klass, "select", env_select, 0);
rb_objc_define_method(klass, "select!", env_select_bang, 0);
rb_objc_define_method(klass, "shift", env_shift, 0);
rb_objc_define_method(klass, "invert", env_invert, 0);
rb_objc_define_method(klass, "replace", env_replace, 1);
Expand Down
4 changes: 0 additions & 4 deletions spec/frozen/tags/macruby/core/env/select_tags.txt

This file was deleted.

0 comments on commit 2839b68

Please sign in to comment.