Method: Array#range_containing

Defined in:
lib/cosmos/core_ext/array.rb

#range_containing(start_value, end_value) ⇒ Range

Returns the range of array elements which contain both the start value and end value.

NOTE: This routine only works on sorted data!

Parameters:

  • start_value (Numeric)

    The start value to search for (must be less than end_value)

  • end_value (Numeric)

    The end value to search for

Returns:

  • (Range)

    The range of array elements which contain both the start_value and end_value



191
192
193
194
# File 'lib/cosmos/core_ext/array.rb', line 191

def range_containing(start_value, end_value)
  raise "end_value: #{end_value} must be greater than start_value: #{start_value}" if end_value < start_value
  Range.new(index_lt_eq(start_value), index_gt_eq(end_value))
end