summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-07 09:31:02 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-07 09:31:02 +0000
commiteda5ffe5245cfd457f2e02bee51c2a61ed001481 (patch)
treef7225f455c33338f94615027a53f7d5dcdf5d8a4 /hash.c
parenta3e284065a7ad36916c34d1a255eb37b11f0aa74 (diff)
* 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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c33
1 files changed, 26 insertions, 7 deletions
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 <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 @@ 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;
@@ -2472,6 +2481,14 @@ env_index(dmy, value)
}
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 @@ 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);