/*
 *  call-seq:
 *     enum.max                   => obj
 *     enum.max {|a,b| block }    => obj
 *
 *  Returns the object in _enum_ with the maximum value. The
 *  first form assumes all objects implement <code>Comparable</code>;
 *  the second uses the block to return <em>a <=> b</em>.
 *
 *     a = %w(albatross dog horse)
 *     a.max                                  #=> "horse"
 *     a.max {|a,b| a.length <=> b.length }   #=> "albatross"
 */

static VALUE
enum_max(VALUE obj)
{
    VALUE result[2];

    result[0] = Qundef;
    if (rb_block_given_p()) {
        result[1] = rb_ary_new3(2, Qnil, Qnil);
        rb_block_call(obj, id_each, 0, 0, max_ii, (VALUE)result);
    }
    else {
        rb_block_call(obj, id_each, 0, 0, max_i, (VALUE)result);
    }
    if (result[0] == Qundef) return Qnil;
    return result[0];
}