max()
public
Returns the maximum value in rng. The second uses the block to
compare values. Returns nil if the first
value in range is larger than the last
value.
static VALUE
range_max(VALUE range)
{
VALUE e = RANGE_END(range);
int ip = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cInteger);
if (rb_block_given_p() || (EXCL(range) && !ip)) {
return rb_call_super(0, 0);
}
else {
VALUE b = RANGE_BEG(range);
int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
if (c > 0)
return Qnil;
if (EXCL(range)) {
if (c == 0) return Qnil;
if (FIXNUM_P(e)) {
return LONG2NUM(FIX2LONG(e) - 1);
}
return rb_funcall(e, '-', 1, INT2FIX(1));
}
return e;
}
}