public Method

Comparable.between?(p1, p2)

obj.between?(min, max)     true or false

Returns false if obj <=> min is less than zero or if anObject <=> max is greater than zero, true otherwise.

3.between?(1, 5)               #=> true
6.between?(1, 5)               #=> false
'cat'.between?('ant', 'dog')   #=> true
'gnu'.between?('ant', 'dog')   #=> false

Source Code

/*
*  call-seq:
*     obj.between?(min, max)    => true or false
*  
*  Returns <code>false</code> if <i>obj</i> <code><=></code>
*  <i>min</i> is less than zero or if <i>anObject</i> <code><=></code>
*  <i>max</i> is greater than zero, <code>true</code> otherwise.
*     
*     3.between?(1, 5)               #=> true
*     6.between?(1, 5)               #=> false
*     'cat'.between?('ant', 'dog')   #=> true
*     'gnu'.between?('ant', 'dog')   #=> false
*     
*/

static VALUE
cmp_between(x, min, max)
   VALUE x, min, max;
{
   if (RTEST(cmp_lt(x, min))) return Qfalse;
   if (RTEST(cmp_gt(x, max))) return Qfalse;
   return Qtrue;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.