Module: RangeOperations::Single

Defined in:
lib/range_operations/single.rb

Class Method Summary collapse

Class Method Details

.backwards?(r) ⇒ Boolean

True if begin is greater than end

Returns:

  • (Boolean)


5
6
7
# File 'lib/range_operations/single.rb', line 5

def self.backwards?(r)
  r && r.begin > r.end
end

.straighten(r) ⇒ Object

Inverts backwards Ranges, leaves others unchanged



10
11
12
# File 'lib/range_operations/single.rb', line 10

def self.straighten(r)
  r.begin <= r.end ? r : r.end .. r.begin
end