class Range
Public Instance Methods
after()
click to toggle source
Return an IntegerRange that captures all the values after the end of the interval @return [IntegerRange] a new Range
# File lib/hf.rb, line 134 def after raise(WrongType, wrong_type_message(Integer)) unless self.begin.is_a?(Integer) (1 + self.end)..-1 end
before()
click to toggle source
Return an IntegerRange that captures all the values before the beginning of the interval @return [IntegerRange] a new Range
# File lib/hf.rb, line 141 def before raise(WrongType, wrong_type_message(Integer)) unless self.begin.is_a?(Integer) 0..(self.begin - 1) end
bump(n)
click to toggle source
Bump the beginning and end of an integer range by n @param n [Integer] the amount to raise both begin and end by @return [IntegerRange] a new Range
# File lib/hf.rb, line 126 def bump(n) raise(WrongType, wrong_type_message(Integer)) unless self.begin.is_a?(Integer) raise(WrongArgumentType, wrong_argument_type_message(Integer, n.class)) unless n.is_a?(Integer) Range.new(self.begin + n, self.end + n, self.exclude_end?) end
Private Instance Methods
wrong_argument_type_message(expected_type, actual_type)
click to toggle source
@param expected_type [ClassName] @param actual_type [ClassName] @return [String] the message for the WrongArgumentType exception
# File lib/hf.rb, line 157 def wrong_argument_type_message(expected_type, actual_type) "Argument must be an #{expected_type} and not a #{actual_type}" end
wrong_type_message(expected_type)
click to toggle source
@param expected_type [ClassName] @return [String] the message for the WrongType exception
# File lib/hf.rb, line 150 def wrong_type_message(expected_type) "Range must have #{expected_type} values and not #{self.begin.class}" end