class Range
Reopened to add some useful methods
Public Instance Methods
empty?()
click to toggle source
Returns whether the range is empty
A range is empty if end < begin or if begin == end and exclude_end? is true.
# File lib/bookie/extensions.rb, line 33 def empty? if exclude_end? self.end <= self.begin else self.end < self.begin end end
exclusive()
click to toggle source
Converts the range to an equivalent exclusive range (one where exclude_end? is true)
Only works for ranges with discrete steps between values (i.e. integers)
# File lib/bookie/extensions.rb, line 21 def exclusive if exclude_end? self else Range.new(self.begin, self.end + 1, true) end end
normalized()
click to toggle source
If end < begin, returns an empty range (begin … begin) Otherwise, returns the original range
# File lib/bookie/extensions.rb, line 9 def normalized if self.end < self.begin self.begin ... self.begin else self end end