Sha256: f50dde41defe4fed46fc335bb4ce61cd1c61d8ce79d757fe27cbc144b95cc872
Contents?: true
Size: 1.21 KB
Versions: 22
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true Range.class_eval do # Allows multiplying a range. This will create a new range due to range objects being immutable. # # @note Make sure to assign this to a new var or do 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
Version data entries
22 entries across 22 versions & 1 rubygems