From eb0c96510a072f35ddcaf418d560e30786e5cef1 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 20 May 2003 06:29:23 +0000 Subject: * eval.c (rb_yield_0): give warning for multiple values for a block parameter. * eval.c (rb_yield_values): a function to yield multiple values. * array.c (sort_1): use rb_yield_values. * enum.c (min_ii, max_ii): ditto. * hash.c (rb_hash_update_block_i, delete_if_i, select_i, each_pair_i, env_each, env_reject_bang, env_select, env_update_i): ditto. * struct.c (rb_struct_each_pair): ditto. * eval.c (top_include): should include module in the current self, not ruby_top_self. [ruby-dev:20198] * eval.c (top_include): stop inclusion to ruby_wrapper; give warning. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 5fadb3ee0..57c580eea 100644 --- a/hash.c +++ b/hash.c @@ -465,7 +465,7 @@ delete_if_i(key, value) VALUE key, value; { if (key == Qundef) return ST_CONTINUE; - if (RTEST(rb_yield(rb_assoc_new(key, value)))) + if (RTEST(rb_yield_values(2, key, value))) return ST_DELETE; return ST_CONTINUE; } @@ -500,12 +500,9 @@ static enum st_retval select_i(key, value, result) VALUE key, value, result; { - VALUE assoc; - if (key == Qundef) return ST_CONTINUE; - assoc = rb_assoc_new(key, value); - if (RTEST(rb_yield(assoc))) - rb_ary_push(result, assoc); + if (RTEST(rb_yield_values(2, key, value))) + rb_ary_push(result, rb_assoc_new(key, value)); return ST_CONTINUE; } @@ -663,7 +660,7 @@ each_pair_i(key, value) VALUE key, value; { if (key == Qundef) return ST_CONTINUE; - rb_yield(rb_assoc_new(key, value)); + rb_yield_values(2, key, value); return ST_CONTINUE; } @@ -938,7 +935,7 @@ rb_hash_update_block_i(key, value, hash) { if (key == Qundef) return ST_CONTINUE; if (rb_hash_has_key(hash, key)) { - value = rb_yield(rb_ary_new3(3, key, rb_hash_aref(hash, key), value)); + value = rb_yield_values(3, key, rb_hash_aref(hash, key), value); } rb_hash_aset(hash, key, value); return ST_CONTINUE; @@ -1334,8 +1331,8 @@ env_each(hash) while (*env) { char *s = strchr(*env, '='); if (s) { - rb_yield(rb_assoc_new(rb_tainted_str_new(*env, s-*env), - rb_tainted_str_new2(s+1))); + rb_yield_values(2, rb_tainted_str_new(*env, s-*env), + rb_tainted_str_new2(s+1)); } env++; } @@ -1359,7 +1356,7 @@ env_reject_bang() while (len--) { VALUE val = rb_f_getenv(Qnil, *ptr); if (!NIL_P(val)) { - if (RTEST(rb_yield(rb_assoc_new(*ptr, val)))) { + if (RTEST(rb_yield_values(2, *ptr, val))) { FL_UNSET(*ptr, FL_TAINT); env_delete(Qnil, *ptr); del++; @@ -1413,10 +1410,10 @@ env_select(argc, argv) while (*env) { char *s = strchr(*env, '='); if (s) { - VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env), - rb_tainted_str_new2(s+1)); - if (RTEST(rb_yield(assoc))) { - rb_ary_push(result, assoc); + VALUE k = rb_tainted_str_new(*env, s-*env); + VALUE v = rb_tainted_str_new2(s+1); + if (RTEST(rb_yield_values(2, k, v))) { + rb_ary_push(result, rb_assoc_new(k, v)); } } env++; @@ -1712,7 +1709,7 @@ env_update_i(key, val) { if (key != Qundef) { if (rb_block_given_p()) { - val = rb_yield(rb_ary_new3(3, key, rb_f_getenv(Qnil, key), val)); + val = rb_yield_values(3, key, rb_f_getenv(Qnil, key), val); } env_aset(Qnil, key, val); } -- cgit