Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities.rb

Instance Method Summary collapse

Instance Method Details

#empty?Boolean

Verify if self is empty

Returns:

  • (Boolean)


17
18
19
# File 'lib/utilities.rb', line 17

def empty?
  count.zero?
end

#intersection(range) ⇒ Object Also known as: &

Return a range containing elements common to the two ranges, with no duplicates



10
11
12
13
# File 'lib/utilities.rb', line 10

def intersection range
  values = self.to_a & range.to_a
  values.empty? ? nil : (values.first..values.last)  
end

#overlap?(range) ⇒ Boolean

Detect if the two ranges overlap one with the other

Returns:

  • (Boolean)


22
23
24
# File 'lib/utilities.rb', line 22

def overlap? range
  !(self & range).nil?
end