Class: Range
Instance Method Summary collapse
-
#cover?(object) ⇒ Boolean
Adds cover? if not defined (like in previous rubies).
-
#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
#cover?(object) ⇒ Boolean
Adds cover? if not defined (like in previous rubies)
20 21 22 23 |
# File 'lib/utilities/range.rb', line 20 def cover? object ends = [self.first, self.last] ends.min <= object && object <= ends.max end |
#empty? ⇒ Boolean
Verify if self is empty
10 11 12 |
# File 'lib/utilities/range.rb', line 10 def empty? count.zero? end |
#intersection(range) ⇒ Object Also known as: &
Return a range containing elements common to the two ranges, with no duplicates
3 4 5 6 |
# File 'lib/utilities/range.rb', line 3 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
15 16 17 |
# File 'lib/utilities/range.rb', line 15 def overlap? range !(self & range).nil? end |