1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/dbm/dbm.c (fdbm_index): make #index warn like Hash.

* ext/dbm/dbm.c (fdbm_key): new method.

* ext/sdbm/init.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-11-07 22:07:05 +00:00
parent 80d16e7403
commit c82769f227
4 changed files with 32 additions and 8 deletions

View file

@ -1,3 +1,11 @@
Sat Nov 8 06:51:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/dbm/dbm.c (fdbm_index): make #index warn like Hash.
* ext/dbm/dbm.c (fdbm_key): new method.
* ext/sdbm/init.c: ditto.
Sat Nov 8 06:20:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/curses/curses.c: curses encoding should obey locale.

View file

@ -198,7 +198,7 @@ fdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
}
static VALUE
fdbm_index(VALUE obj, VALUE valstr)
fdbm_key(VALUE obj, VALUE valstr)
{
datum key, val;
struct dbmdata *dbmp;
@ -219,6 +219,13 @@ fdbm_index(VALUE obj, VALUE valstr)
return Qnil;
}
static VALUE
fdbm_index(VALUE hash, VALUE value)
{
rb_warn("DBM#index is deprecated; use DBM#key");
return fdbm_key(hash, value);
}
static VALUE
fdbm_select(VALUE obj)
{
@ -692,6 +699,7 @@ Init_dbm(void)
rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
rb_define_method(rb_cDBM, "store", fdbm_store, 2);
rb_define_method(rb_cDBM, "index", fdbm_index, 1);
rb_define_method(rb_cDBM, "key", fdbm_key, 1);
rb_define_method(rb_cDBM, "select", fdbm_select, 0);
rb_define_method(rb_cDBM, "values_at", fdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fdbm_length, 0);

View file

@ -176,7 +176,7 @@ fsdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
}
static VALUE
fsdbm_index(VALUE obj, VALUE valstr)
fsdbm_key(VALUE obj, VALUE valstr)
{
datum key, val;
struct dbmdata *dbmp;
@ -196,6 +196,13 @@ fsdbm_index(VALUE obj, VALUE valstr)
return Qnil;
}
static VALUE
fsdbm_index(VALUE hash, VALUE value)
{
rb_warn("SDBM#index is deprecated; use SDBM#key");
return fsdbm_key(hash, value);
}
static VALUE
fsdbm_select(VALUE obj)
{
@ -671,6 +678,7 @@ Init_sdbm()
rb_define_method(rb_cDBM, "[]=", fsdbm_store, 2);
rb_define_method(rb_cDBM, "store", fsdbm_store, 2);
rb_define_method(rb_cDBM, "index", fsdbm_index, 1);
rb_define_method(rb_cDBM, "index", fsdbm_key, 1);
rb_define_method(rb_cDBM, "select", fsdbm_select, 0);
rb_define_method(rb_cDBM, "values_at", fsdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fsdbm_length, 0);

View file

@ -160,9 +160,9 @@ if defined? DBM
}
end
def test_index
def test_key
assert_equal('bar', @dbm['foo'] = 'bar')
assert_equal('foo', @dbm.index('bar'))
assert_equal('foo', @dbm.key('bar'))
assert_nil(@dbm['bar'])
end
@ -217,7 +217,7 @@ if defined? DBM
n = 0
ret = @dbm.each_pair {|key, val|
assert_not_nil(i = keys.index(key))
assert_not_nil(i = keys.key(key))
assert_equal(val, values[i])
n += 1
@ -238,8 +238,8 @@ if defined? DBM
n = 0
ret = @dbm.each_value {|val|
assert_not_nil(key = @dbm.index(val))
assert_not_nil(i = keys.index(key))
assert_not_nil(key = @dbm.key(val))
assert_not_nil(i = keys.key(key))
assert_equal(val, values[i])
n += 1
@ -260,7 +260,7 @@ if defined? DBM
n = 0
ret = @dbm.each_key {|key|
assert_not_nil(i = keys.index(key))
assert_not_nil(i = keys.key(key))
assert_equal(@dbm[key], values[i])
n += 1