Пример #1
0
int
rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
{
    VALUE b, e;
    int excl;

    if (rb_obj_is_kind_of(range, rb_cRange)) {
        b = RANGE_BEG(range);
        e = RANGE_END(range);
        excl = EXCL(range);
    }
    else {
	if (!rb_vm_respond_to(range, selBeg, false)) {
	    return 0;
	}
	if (!rb_vm_respond_to(range, selEnd, false)) {
	    return 0;
	}
	b = rb_vm_call(range, selBeg, 0, NULL);
	e = rb_vm_call(range, selEnd, 0, NULL);
	excl = RTEST(rb_vm_call(range, selExcludeEnd, 0, NULL));
    }
    *begp = b;
    *endp = e;
    *exclp = excl;
    return 1;
}
Пример #2
0
static VALUE
exc_equal(VALUE exc, SEL sel, VALUE obj)
{
    VALUE mesg, backtrace;
    if (exc == obj) {
	return Qtrue;
    }
    ID id_mesg = rb_intern("mesg");
    if (rb_obj_class(exc) != rb_obj_class(obj)) {
	SEL sel_message = sel_registerName("message");
	SEL sel_backtrace = sel_registerName("backtrace");
	if (!rb_vm_respond_to(obj, sel_message, false)
		|| !rb_vm_respond_to(obj, sel_backtrace, false)) {
	    return Qfalse;
	}
	mesg = rb_vm_call(obj, sel_message, 0, NULL);
	backtrace = rb_vm_call(obj, sel_backtrace, 0, NULL);
    }
    else {
        mesg = rb_attr_get(obj, id_mesg);
        backtrace = exc_backtrace(obj, 0);
    }
    if (!rb_equal(rb_attr_get(exc, id_mesg), mesg)) {
        return Qfalse;
    }
    if (!rb_equal(exc_backtrace(exc, 0), backtrace)) {
        return Qfalse;
    }
    return Qtrue;
}
Пример #3
0
int
rb_obj_respond_to(VALUE obj, ID id, int priv)
{
    const char *id_name = rb_id2name(id);
    SEL sel = sel_registerName(id_name);
    if (!rb_vm_respond_to(obj, sel, priv)) {
	char buf[100];
	snprintf(buf, sizeof buf, "%s:", id_name);
	sel = sel_registerName(buf);
	return rb_vm_respond_to(obj, sel, priv) == true ? 1 : 0;
    }
    return 1;
}
Пример #4
0
static VALUE
interpret_value(rb_yaml_parser_t *parser, VALUE result, VALUE handler)
{
    if (NIL_P(handler)) {
	return result;
    }
    if (rb_vm_respond_to(handler, sel_call, 0)) {
	return rb_vm_call(handler, sel_call, 1, &result);
    }
    else if (rb_vm_respond_to(handler, sel_yaml_new, 0)) {
	return rb_vm_call(handler, sel_yaml_new, 1, &result);
    }
    return result;
}
Пример #5
0
static int
discrete_object_p(VALUE obj)
{
    if (rb_obj_is_kind_of(obj, rb_cTime)) return FALSE; /* until Time#succ removed */
    return rb_vm_respond_to(obj, selSucc, false);
}