Class: Range

Inherits:
Object
  • Object
show all
Includes:
BetterRanges::RangeOperators, Comparable
Defined in:
lib/better_ranges/sparse_range.rb,
lib/better_ranges/range_operators.rb

Instance Method Summary collapse

Methods included from BetterRanges::RangeOperators

#&, #-, #|

Instance Method Details

#<=>(other) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/better_ranges/sparse_range.rb', line 233

def <=>(other)
  comp = nil
  if other.is_a?(Range) || other.is_a?(BetterRanges::SparseRange)
    comp = (first <=> other.first)
    comp = (last <=> other.last) if comp == 0
    if comp == 0
      comp = -1 if exclude_end? && !other.exclude_end?
      comp = 1 if !exclude_end? && other.exclude_end?
    end
  else
    comp = (first <=> other)
    comp = (last <=> other) if comp == 0
    comp = -1 if comp == 0 && exclude_end?
  end
  comp
end