From 373282f6656d3d3d989d261e7a95f8e81b5c9712 Mon Sep 17 00:00:00 2001 From: ocean Date: Sat, 2 Apr 2005 04:23:56 +0000 Subject: [PATCH] * hash.c (env_key): ENV.index is deprecated as well as Hash#index. use ENV.key instead. [ruby-dev:25974] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ hash.c | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7f4a5e660..aefb42e55b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Apr 2 13:23:17 2005 Hirokazu Yamamoto + + * hash.c (env_key): ENV.index is deprecated as well as Hash#index. + use ENV.key instead. [ruby-dev:25974] + Sat Apr 2 02:19:11 2005 Hidetoshi NAGAI * ext/tk/lib/tk.rb (TkWindow.initialize): accept 'without_creating' diff --git a/hash.c b/hash.c index 58c6576fd2..9c96e8e7db 100644 --- a/hash.c +++ b/hash.c @@ -591,8 +591,8 @@ key_i(key, value, args) * 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 * */ @@ -2317,7 +2317,7 @@ env_has_value(dmy, value) } static VALUE -env_index(dmy, value) +env_key(dmy, value) VALUE dmy, value; { char **env; @@ -2342,6 +2342,14 @@ env_index(dmy, value) return Qnil; } +static VALUE +env_index(dmy, value) + VALUE dmy, value; +{ + rb_warn("ENV.index is deprecated; use ENV.key"); + return env_key(dmy, value); +} + static VALUE env_to_hash() { @@ -2559,6 +2567,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,"size", env_size, 0); rb_define_singleton_method(envtbl,"length", env_size, 0);