Class: Range
- Inherits:
-
Object
- Object
- Range
- Defined in:
- lib/utilities.rb
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Verify if self is empty.
-
#intersection(range) ⇒ Object
(also: #&)
Return a range containing elements common to the two ranges, with no duplicates.
-
#overlap?(range) ⇒ Boolean
Detect if the two ranges overlap one with the other.
Instance Method Details
#empty? ⇒ Boolean
Verify if self is empty
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
22 23 24 |
# File 'lib/utilities.rb', line 22 def overlap? range !(self & range).nil? end |