Method: Enumerable#partial_sort

Defined in:
lib/jinx/helpers/enumerable.rb

#partial_sortEnumerable

Sorts this collection’s members with a partial sort operator, i.e. the comparison returns -1, 0, 1 or nil. The resulting sorted order places each non-nil comparable items in the sort order. The order of nil comparison items is indeterminate.

Examples:

[Array, Numeric, Enumerable, Set].partial_sort #=> [Array, Numeric, Set, Enumerable]

Returns:

  • the items in this collection in partial sort order



227
228
229
230
# File 'lib/jinx/helpers/enumerable.rb', line 227

def partial_sort
  unless block_given? then return partial_sort { |item1, item2| item1 <=> item2 } end
  sort { |item1, item2| yield(item1, item2) or 1 }
end