diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-03 14:07:48 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-03 14:07:48 +0000 |
commit | 6e8eea7abe958e7323e0941687ca2e917426d681 (patch) | |
tree | 3d714f6a0d12fb29aa1a87e325629c33b666f7da | |
parent | fbc00c877258057fe282659cf5e7d0a1c9dcc80e (diff) | |
download | ruby-6e8eea7abe958e7323e0941687ca2e917426d681.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | hash.c | 70 | ||||
-rw-r--r-- | version.h | 6 |
3 files changed, 20 insertions, 63 deletions
@@ -1,3 +1,10 @@ +Sat Nov 3 22:49:37 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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 <akr@fsij.org> * configure.in: --with-vendor-hdrdir implemented. @@ -1084,39 +1084,6 @@ static int each_pair_i(VALUE key, VALUE value) { if (key == Qundef) return ST_CONTINUE; - rb_yield_values(2, key, value); - return ST_CONTINUE; -} - -/* - * call-seq: - * hsh.each_pair {| key_value_array | block } -> hsh - * - * Calls <i>block</i> once for each key in <i>hsh</i>, passing the - * key and value to the block as a two-element array. - * - * h = { "a" => 100, "b" => 200 } - * h.each_pair {|(key, value)| puts "#{key} is #{value}" } - * - * <em>produces:</em> - * - * a is 100 - * b is 200 - * - */ - -static VALUE -rb_hash_each_pair(VALUE hash) -{ - RETURN_ENUMERATOR(hash, 0, 0); - rb_hash_foreach(hash, each_pair_i, 0); - 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; } @@ -1124,10 +1091,10 @@ each_i(VALUE key, VALUE value) /* * call-seq: * hsh.each {| key, value | block } -> hsh + * hsh.each_pair {| key, value | block } -> hsh * * Calls <i>block</i> once for each key in <i>hsh</i>, passing the key-value - * pair as parameters. Also see <code>Hash#each_pair</code>, which - * passes the key and value to the block as a two-element array. + * pair as parameters. * * h = { "a" => 100, "b" => 200 } * h.each {|key, value| puts "#{key} is #{value}" } @@ -1140,10 +1107,10 @@ each_i(VALUE key, VALUE value) */ static VALUE -rb_hash_each(VALUE hash) +rb_hash_each_pair(VALUE hash) { RETURN_ENUMERATOR(hash, 0, 0); - rb_hash_foreach(hash, each_i, 0); + rb_hash_foreach(hash, each_pair_i, 0); return hash; } @@ -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,31 +2123,12 @@ env_each_i(VALUE ehash, int values) FREE_ENVIRON(environ); for (i=0; i<RARRAY_LEN(ary); i+=2) { - if (values) { - rb_yield_values(2, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]); - } - else { - rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1])); - } + rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1])); } return ehash; } static VALUE -env_each(VALUE ehash) -{ - RETURN_ENUMERATOR(ehash, 0, 0); - return env_each_i(ehash, Qtrue); -} - -static VALUE -env_each_pair(VALUE ehash) -{ - RETURN_ENUMERATOR(ehash, 0, 0); - return env_each_i(ehash, Qfalse); -} - -static VALUE env_reject_bang(void) { volatile VALUE keys; @@ -2622,10 +2572,10 @@ Init_Hash(void) rb_define_method(rb_cHash,"length", rb_hash_size, 0); rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0); - rb_define_method(rb_cHash,"each", rb_hash_each, 0); rb_define_method(rb_cHash,"each_value", rb_hash_each_value, 0); rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 0); rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0); + rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0); rb_define_method(rb_cHash,"keys", rb_hash_keys, 0); rb_define_method(rb_cHash,"values", rb_hash_values, 0); @@ -2666,7 +2616,7 @@ Init_Hash(void) rb_define_singleton_method(envtbl,"fetch", env_fetch, -1); rb_define_singleton_method(envtbl,"[]=", env_aset, 2); rb_define_singleton_method(envtbl,"store", env_aset, 2); - rb_define_singleton_method(envtbl,"each", env_each, 0); + rb_define_singleton_method(envtbl,"each", env_each_pair, 0); rb_define_singleton_method(envtbl,"each_pair", env_each_pair, 0); rb_define_singleton_method(envtbl,"each_key", env_each_key, 0); rb_define_singleton_method(envtbl,"each_value", env_each_value, 0); @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-11-02" +#define RUBY_RELEASE_DATE "2007-11-03" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20071102 +#define RUBY_RELEASE_CODE 20071103 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 2 +#define RUBY_RELEASE_DAY 3 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; |