From eda5ffe5245cfd457f2e02bee51c2a61ed001481 Mon Sep 17 00:00:00 2001 From: knu Date: Fri, 7 Nov 2008 09:31:02 +0000 Subject: * hash.c (rb_hash_key, env_key): Hash#index is renamed to Hash#key, and ENV.index to ENV.key. [ruby-dev:37028] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ NEWS | 8 ++++++++ hash.c | 33 ++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 794d2aa0c6..a6d9a2ca7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 7 18:29:09 2008 Akinori MUSHA + + * hash.c (rb_hash_key, env_key): Hash#index is renamed to + Hash#key, and ENV.index to ENV.key. [ruby-dev:37028] + Fri Nov 7 02:08:04 2008 Shugo Maeda * lib/rexml/entity.rb (unnormalized): do not call diff --git a/NEWS b/NEWS index 39223610fd..96721611ff 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,14 @@ with all sufficient information, see the ChangeLog file. New method. + * Hash#key + + Renamed from Hash#index. + + * ENV.key + + Renamed from ENV.index. + * set Set#classify diff --git a/hash.c b/hash.c index 3fe1ff8bb8..f4297589d2 100644 --- a/hash.c +++ b/hash.c @@ -646,7 +646,7 @@ rb_hash_set_default_proc(hash, proc) } static int -index_i(key, value, args) +key_i(key, value, args) VALUE key, value; VALUE *args; { @@ -676,18 +676,18 @@ rb_hash_delete_key(hash, key) /* * call-seq: - * hsh.index(value) => key + * hsh.key(value) => key * * Returns the key for a given value. If not found, returns nil. * * h = { "a" => 100, "b" => 200 } - * h.index(200) #=> "b" - * h.index(999) #=> nil + * h.key(200) #=> "b" + * h.key(999) #=> nil * */ static VALUE -rb_hash_index(hash, value) +rb_hash_key(hash, value) VALUE hash, value; { VALUE args[2]; @@ -695,11 +695,20 @@ rb_hash_index(hash, value) args[0] = value; args[1] = Qnil; - rb_hash_foreach(hash, index_i, (st_data_t)args); + rb_hash_foreach(hash, key_i, (st_data_t)args); return args[1]; } +/* :nodoc: */ +static VALUE +rb_hash_index(hash, value) + VALUE hash, value; +{ + rb_warning("Hash#index is deprecated and will be removed in 1.9; use Hash#key"); + return rb_hash_key(hash, value); +} + /* * call-seq: * hsh.indexes(key, ...) => array @@ -2446,7 +2455,7 @@ env_has_value(dmy, value) } static VALUE -env_index(dmy, value) +env_key(dmy, value) VALUE dmy, value; { char **env; @@ -2471,6 +2480,14 @@ env_index(dmy, value) return Qnil; } +static VALUE +env_index(dmy, value) + VALUE dmy, value; +{ + rb_warning("ENV.index is deprecated and will be removed in 1.9; use ENV.key"); + return env_key(dmy, value); +} + static VALUE env_indexes(argc, argv) int argc; @@ -2682,6 +2699,7 @@ Init_Hash() rb_define_method(rb_cHash,"default=", rb_hash_set_default, 1); rb_define_method(rb_cHash,"default_proc", rb_hash_default_proc, 0); rb_define_method(rb_cHash,"default_proc=", rb_hash_set_default_proc, 1); + rb_define_method(rb_cHash,"key", rb_hash_key, 1); rb_define_method(rb_cHash,"index", rb_hash_index, 1); rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1); rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1); @@ -2746,6 +2764,7 @@ Init_Hash() rb_define_singleton_method(envtbl,"rehash", env_none, 0); rb_define_singleton_method(envtbl,"to_a", env_to_a, 0); rb_define_singleton_method(envtbl,"to_s", env_to_s, 0); + rb_define_singleton_method(envtbl,"key", env_key, 1); rb_define_singleton_method(envtbl,"index", env_index, 1); rb_define_singleton_method(envtbl,"indexes", env_indexes, -1); rb_define_singleton_method(envtbl,"indices", env_indexes, -1); -- cgit v1.2.3