Sha256: 02aa5896355ba4b644e8b35d80ed0d29963db674726254dbcf9df259409b4aa1
Contents?: true
Size: 1.3 KB
Versions: 6
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true Range.class_eval do unless method_defined?(:+) # Allows adding a to a range. This will create a new range since ranges are immutable. # # @note Make sure to assign this to a new var or inline replacement `+=`. # # @raise [RubyRailsExtensions::Errors::NonNumericError] # # @param other [Numeric, Range<Numeric>] # # @return [Range] # def +(other) unless self.begin.is_a?(Numeric) raise( RubyRailsExtensions::Errors::NonNumericError, "Wrong range type (given #{self.begin.class}, expected Numeric)" ) end new_begin, new_end = if other.is_a?(Range) unless other.begin.is_a?(Numeric) raise( RubyRailsExtensions::Errors::NonNumericError, "Wrong range type (given #{other.begin.class}, expected Numeric)" ) end [self.begin + other.begin, self.end + other.end] else unless other.is_a?(Numeric) raise( RubyRailsExtensions::Errors::NonNumericError, "Wrong type (given #{other.class}, expected Numeric)" ) end [self.begin + other, self.end + other] end Range.new(new_begin, new_end, exclude_end?) end end end
Version data entries
6 entries across 6 versions & 1 rubygems