1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2007-11-03 14:07:48 +00:00
parent fbc00c8772
commit 6e8eea7abe
3 changed files with 22 additions and 65 deletions

View file

@ -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.

74
hash.c
View file

@ -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 <i>block</i> once for each key in <i>hsh</i>, passing the
* key and value to the block as a two-element array.
* Calls <i>block</i> once for each key in <i>hsh</i>, 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}" }
*
* <em>produces:</em>
*
@ -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 <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.
*
* h = { "a" => 100, "b" => 200 }
* h.each {|key, value| puts "#{key} is #{value}" }
*
* <em>produces:</em>
*
* 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<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)
{
@ -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);

View file

@ -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[];