Method: Enumerable#min_by

Defined in:
enum.c

#min_by {|obj| ... } ⇒ Object #min_byObject

Returns the object in enum that gives the minimum value from the given block.

If no block is given, an enumerator is returned instead.

a = %w(albatross dog horse)
a.min_by { |x| x.length }   #=> "dog"

Overloads:

  • #min_by {|obj| ... } ⇒ Object

    Yields:

    • (obj)

    Returns:



1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
# File 'enum.c', line 1500

static VALUE
enum_min_by(VALUE obj)
{
    NODE *memo;

    RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);

    memo = NEW_MEMO(Qundef, Qnil, 0);
    rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
    return memo->u2.value;
}