diff --git a/ChangeLog b/ChangeLog index 2767555352..f7404bfe4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Nov 3 22:49:37 2007 Yukihiro Matsumoto + + * hash.c (rb_hash_each_pair): make Hash#each to be alias to + Hash#each_pair for compatibility and clarity. + + * hash.c (env_each_pair): ditto. + Sat Nov 3 22:41:05 2007 Tanaka Akira * configure.in: --with-vendor-hdrdir implemented. diff --git a/hash.c b/hash.c index 821bfcbb8a..385e056248 100644 --- a/hash.c +++ b/hash.c @@ -1084,19 +1084,20 @@ static int each_pair_i(VALUE key, VALUE value) { if (key == Qundef) return ST_CONTINUE; - rb_yield_values(2, key, value); + rb_yield(rb_assoc_new(key, value)); return ST_CONTINUE; } /* * call-seq: - * hsh.each_pair {| key_value_array | block } -> hsh + * hsh.each {| key, value | block } -> hsh + * hsh.each_pair {| key, value | block } -> hsh * - * Calls block once for each key in hsh, passing the - * key and value to the block as a two-element array. + * Calls block once for each key in hsh, passing the key-value + * pair as parameters. * * h = { "a" => 100, "b" => 200 } - * h.each_pair {|(key, value)| puts "#{key} is #{value}" } + * h.each {|key, value| puts "#{key} is #{value}" } * * produces: * @@ -1113,40 +1114,6 @@ rb_hash_each_pair(VALUE hash) return hash; } -static int -each_i(VALUE key, VALUE value) -{ - if (key == Qundef) return ST_CONTINUE; - rb_yield(rb_assoc_new(key, value)); - return ST_CONTINUE; -} - -/* - * call-seq: - * hsh.each {| key, value | block } -> hsh - * - * Calls block once for each key in hsh, passing the key-value - * pair as parameters. Also see Hash#each_pair, which - * passes the key and value to the block as a two-element array. - * - * h = { "a" => 100, "b" => 200 } - * h.each {|key, value| puts "#{key} is #{value}" } - * - * produces: - * - * a is 100 - * b is 200 - * - */ - -static VALUE -rb_hash_each(VALUE hash) -{ - RETURN_ENUMERATOR(hash, 0, 0); - rb_hash_foreach(hash, each_i, 0); - return hash; -} - static int to_a_i(VALUE key, VALUE value, VALUE ary) { @@ -2134,12 +2101,14 @@ env_each_value(VALUE ehash) } static VALUE -env_each_i(VALUE ehash, int values) +env_each_pair(VALUE ehash) { char **env; VALUE ary; long i; + RETURN_ENUMERATOR(ehash, 0, 0); + rb_secure(4); ary = rb_ary_new(); env = GET_ENVIRON(environ); @@ -2154,30 +2123,11 @@ env_each_i(VALUE ehash, int values) FREE_ENVIRON(environ); for (i=0; i