* 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:
parent
fbc00c8772
commit
6e8eea7abe
@ -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>
|
Sat Nov 3 22:41:05 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* configure.in: --with-vendor-hdrdir implemented.
|
* configure.in: --with-vendor-hdrdir implemented.
|
||||||
|
74
hash.c
74
hash.c
@ -1084,19 +1084,20 @@ static int
|
|||||||
each_pair_i(VALUE key, VALUE value)
|
each_pair_i(VALUE key, VALUE value)
|
||||||
{
|
{
|
||||||
if (key == Qundef) return ST_CONTINUE;
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
rb_yield_values(2, key, value);
|
rb_yield(rb_assoc_new(key, value));
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* 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
|
* Calls <i>block</i> once for each key in <i>hsh</i>, passing the key-value
|
||||||
* key and value to the block as a two-element array.
|
* pair as parameters.
|
||||||
*
|
*
|
||||||
* h = { "a" => 100, "b" => 200 }
|
* 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>
|
* <em>produces:</em>
|
||||||
*
|
*
|
||||||
@ -1113,40 +1114,6 @@ rb_hash_each_pair(VALUE hash)
|
|||||||
return 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
|
static int
|
||||||
to_a_i(VALUE key, VALUE value, VALUE ary)
|
to_a_i(VALUE key, VALUE value, VALUE ary)
|
||||||
{
|
{
|
||||||
@ -2134,12 +2101,14 @@ env_each_value(VALUE ehash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
env_each_i(VALUE ehash, int values)
|
env_each_pair(VALUE ehash)
|
||||||
{
|
{
|
||||||
char **env;
|
char **env;
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
|
RETURN_ENUMERATOR(ehash, 0, 0);
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new();
|
||||||
env = GET_ENVIRON(environ);
|
env = GET_ENVIRON(environ);
|
||||||
@ -2154,30 +2123,11 @@ env_each_i(VALUE ehash, int values)
|
|||||||
FREE_ENVIRON(environ);
|
FREE_ENVIRON(environ);
|
||||||
|
|
||||||
for (i=0; i<RARRAY_LEN(ary); i+=2) {
|
for (i=0; i<RARRAY_LEN(ary); i+=2) {
|
||||||
if (values) {
|
rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]));
|
||||||
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]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ehash;
|
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
|
static VALUE
|
||||||
env_reject_bang(void)
|
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,"length", rb_hash_size, 0);
|
||||||
rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 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_value", rb_hash_each_value, 0);
|
||||||
rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 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_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,"keys", rb_hash_keys, 0);
|
||||||
rb_define_method(rb_cHash,"values", rb_hash_values, 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,"fetch", env_fetch, -1);
|
||||||
rb_define_singleton_method(envtbl,"[]=", env_aset, 2);
|
rb_define_singleton_method(envtbl,"[]=", env_aset, 2);
|
||||||
rb_define_singleton_method(envtbl,"store", 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_pair", env_each_pair, 0);
|
||||||
rb_define_singleton_method(envtbl,"each_key", env_each_key, 0);
|
rb_define_singleton_method(envtbl,"each_key", env_each_key, 0);
|
||||||
rb_define_singleton_method(envtbl,"each_value", env_each_value, 0);
|
rb_define_singleton_method(envtbl,"each_value", env_each_value, 0);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#define RUBY_VERSION "1.9.0"
|
#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_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20071102
|
#define RUBY_RELEASE_CODE 20071103
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 11
|
#define RUBY_RELEASE_MONTH 11
|
||||||
#define RUBY_RELEASE_DAY 2
|
#define RUBY_RELEASE_DAY 3
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user