Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Array#bsearch
() { (Elem element) -> bool? } -> Elem?
() { (Elem element) -> ::Numeric? } -> Elem?
() -> ::Enumerator[Elem, Elem?]
bsearch {|element| ... } → found_element or nil
bsearch → new_enumerator
array.c
View on GitHub ↗
static VALUE
rb_ary_bsearch(VALUE ary)
{
VALUE index_result = rb_ary_bsearch_index(ary);
if (FIXNUM_P(index_result)) {
return rb_ary_entry(ary, FIX2LONG(index_result));
}
return index_result;
}
Returns the element from self found by a binary search, or nil if the search found no suitable element.
See Binary Searching.
Related: see Methods for Fetching.