Skip to content

Commit

Permalink
make GDBM#index warn like Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jan 7, 2013
1 parent 4ada9e4 commit 9ffcd97
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ext/gdbm/gdbm.c
Expand Up @@ -410,13 +410,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;
Expand All @@ -438,6 +438,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
Expand Down Expand Up @@ -1194,6 +1202,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);
Expand Down

0 comments on commit 9ffcd97

Please sign in to comment.