Project

General

Profile

num_clamp.c

0x0dea (D.E. Akers), 06/30/2015 02:18 AM

 
1
static VALUE
2
num_clamp(VALUE num, VALUE obj)
3
{
4
    VALUE begp, endp;
5
    int exclp;
6

    
7
    if (!rb_range_values(obj, &begp, &endp, &exclp)) {
8
        rb_raise(rb_eArgError, "argument must be a Range");
9
    }
10

    
11
    if (exclp) endp = rb_funcall(endp, rb_intern("pred"), 0);
12
    if (rb_funcall(num, idLT, 1, begp)) {
13
        return begp;
14
    } else if (rb_funcall(num, idGT, 1, endp)) {
15
        return endp;
16
    }
17

    
18
    return num;
19
}