minmax_by()
public
Returns two elements array array containing the objects in enum
that gives the minimum and maximum values respectively from the given
block.
If no block is given, an enumerator is returned instead.
a = %w(albatross dog horse)
a.minmax_by {|x| x.length }
Show source
static VALUE
enum_minmax_by(VALUE obj)
{
struct minmax_by_t memo;
RETURN_ENUMERATOR(obj, 0, 0);
memo.min_bv = Qundef;
memo.max_bv = Qundef;
memo.min = Qnil;
memo.max = Qnil;
memo.last_bv = Qundef;
memo.last = Qundef;
rb_block_call(obj, id_each, 0, 0, minmax_by_i, (VALUE)&memo);
if (memo.last_bv != Qundef)
minmax_by_i_update(memo.last_bv, memo.last_bv, memo.last, memo.last, &memo);
return rb_assoc_new(memo.min, memo.max);
}