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

* ext/gdbm/gdbm.c (fgdbm_index): make #index warn like Hash.

[ruby-dev:37039]

* ext/sdbm/init.c (Init_sdbm): typo fixed.  [ruby-dev:37039]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-11-08 03:15:28 +00:00
parent 0042ccef2c
commit 703fb3d9be
5 changed files with 25 additions and 9 deletions

View file

@ -1,3 +1,10 @@
Sat Nov 8 12:10:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/gdbm/gdbm.c (fgdbm_index): make #index warn like Hash.
[ruby-dev:37039]
* ext/sdbm/init.c (Init_sdbm): typo fixed. [ruby-dev:37039]
Sat Nov 8 07:07:48 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: detect stdio buffer pointers for uClibc. a patch

View file

@ -396,13 +396,13 @@ fgdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
/*
* call-seq:
* gdbm.index(value) -> key
* gdbm.key(value) -> key
*
* Returns the _key_ for a given _value_. If several keys may map to the
* same value, the key that is found first will be returned.
*/
static VALUE
fgdbm_index(VALUE obj, VALUE valstr)
fgdbm_key(VALUE obj, VALUE valstr)
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@ -424,6 +424,14 @@ fgdbm_index(VALUE obj, VALUE valstr)
return Qnil;
}
/* :nodoc: */
static VALUE
fgdbm_index(VALUE obj, VALUE value)
{
rb_warn("GDBM#index is deprecated; use GDBM#key");
return fgdbm_key(obj, value);
}
/*
* call-seq:
* gdbm.select { |value| block } -> array
@ -1180,6 +1188,7 @@ Init_gdbm(void)
rb_define_method(rb_cGDBM, "[]=", fgdbm_store, 2);
rb_define_method(rb_cGDBM, "store", fgdbm_store, 2);
rb_define_method(rb_cGDBM, "index", fgdbm_index, 1);
rb_define_method(rb_cGDBM, "key", fgdbm_key, 1);
rb_define_method(rb_cGDBM, "select", fgdbm_select, 0);
rb_define_method(rb_cGDBM, "values_at", fgdbm_values_at, -1);
rb_define_method(rb_cGDBM, "length", fgdbm_length, 0);

View file

@ -678,7 +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, "key", 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

@ -217,7 +217,7 @@ if defined? DBM
n = 0
ret = @dbm.each_pair {|key, val|
assert_not_nil(i = keys.key(key))
assert_not_nil(i = keys.index(key))
assert_equal(val, values[i])
n += 1
@ -239,7 +239,7 @@ if defined? DBM
n = 0
ret = @dbm.each_value {|val|
assert_not_nil(key = @dbm.key(val))
assert_not_nil(i = keys.key(key))
assert_not_nil(i = keys.index(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.key(key))
assert_not_nil(i = keys.index(key))
assert_equal(@dbm[key], values[i])
n += 1

View file

@ -276,9 +276,9 @@ if defined? GDBM
}
end
def test_index
def test_key
assert_equal('bar', @gdbm['foo'] = 'bar')
assert_equal('foo', @gdbm.index('bar'))
assert_equal('foo', @gdbm.key('bar'))
assert_nil(@gdbm['bar'])
end
@ -354,7 +354,7 @@ if defined? GDBM
n = 0
ret = @gdbm.each_value {|val|
assert_not_nil(key = @gdbm.index(val))
assert_not_nil(key = @gdbm.key(val))
assert_not_nil(i = keys.index(key))
assert_equal(val, values[i])