Module: Enumerable

Defined in:
lib/mongo_oplog_backup/ext/enumerable.rb

Overview

Define Enumerable#sorted?

Instance Method Summary collapse

Instance Method Details

#increasing?Boolean

Strictly increasing, in other words sorted and unique

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/mongo_oplog_backup/ext/enumerable.rb', line 12

def increasing?
  each_cons(2).all? do |a, b|
    (a <=> b) < 0
  end
end

#sorted?Boolean

Sorted in ascending order

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/mongo_oplog_backup/ext/enumerable.rb', line 5

def sorted?
  each_cons(2).all? do |a, b|
    (a <=> b) <= 0
  end
end