Exemplo n.º 1
0
Arquivo: dbm.c Projeto: Shopify/ruby
/*
 * call-seq:
 *   DBM.open(filename[, mode[, flags]]) -> dbm
 *   DBM.open(filename[, mode[, flags]]) {|dbm| block}
 *
 * Open a dbm database and yields it if a block is given. See also
 * <code>DBM.new</code>.
 */
static VALUE
fdbm_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);

    if (NIL_P(fdbm_initialize(argc, argv, obj))) {
	return Qnil;
    }

    if (rb_block_given_p()) {
        return rb_ensure(rb_yield, obj, fdbm_close, obj);
    }

    return obj;
}
Exemplo n.º 2
0
Arquivo: dbm.c Projeto: 0x00evil/ruby
/*
 * call-seq:
 *   DBM.open(filename[, mode[, flags]]) -> dbm
 *   DBM.open(filename[, mode[, flags]]) {|dbm| block}
 *
 * Open a dbm database and yields it if a block is given. See also
 * <code>DBM.new</code>.
 */
static VALUE
fdbm_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE obj = fdbm_alloc(klass);

    if (NIL_P(fdbm_initialize(argc, argv, obj))) {
	return Qnil;
    }

    if (rb_block_given_p()) {
        return rb_ensure(rb_yield, obj, fdbm_close, obj);
    }

    return obj;
}