ruby-changes:8595
From: knu <ko1@a...>
Date: Fri, 7 Nov 2008 18:31:30 +0900 (JST)
Subject: [ruby-changes:8595] Ruby:r20130 (ruby_1_8): * hash.c (rb_hash_key, env_key): Hash#index is renamed to
knu 2008-11-07 18:31:02 +0900 (Fri, 07 Nov 2008) New Revision: 20130 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20130 Log: * hash.c (rb_hash_key, env_key): Hash#index is renamed to Hash#key, and ENV.index to ENV.key. [ruby-dev:37028] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/NEWS branches/ruby_1_8/hash.c Index: ruby_1_8/hash.c =================================================================== --- ruby_1_8/hash.c (revision 20129) +++ ruby_1_8/hash.c (revision 20130) @@ -646,7 +646,7 @@ } static int -index_i(key, value, args) +key_i(key, value, args) VALUE key, value; VALUE *args; { @@ -676,18 +676,18 @@ /* * call-seq: - * hsh.index(value) => key + * hsh.key(value) => key * * Returns the key for a given value. If not found, returns <code>nil</code>. * * 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 @@ 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 @@ } static VALUE -env_index(dmy, value) +env_key(dmy, value) VALUE dmy, value; { char **env; @@ -2472,6 +2481,14 @@ } 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; VALUE *argv; @@ -2682,6 +2699,7 @@ 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 @@ 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); Index: ruby_1_8/NEWS =================================================================== --- ruby_1_8/NEWS (revision 20129) +++ ruby_1_8/NEWS (revision 20130) @@ -30,6 +30,14 @@ New method. + * Hash#key + + Renamed from Hash#index. + + * ENV.key + + Renamed from ENV.index. + * set Set#classify Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 20129) +++ ruby_1_8/ChangeLog (revision 20130) @@ -1,3 +1,8 @@ +Fri Nov 7 18:29:09 2008 Akinori MUSHA <knu@i...> + + * 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 <shugo@r...> * lib/rexml/entity.rb (unnormalized): do not call -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/