Sha256: 9d16157c1fd0ed1b99e2ec8c935d05bb84a61a3b3966e4663ed99c1873783ba1
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
class ValuesBase private def self.verify_kind_of(parameter_name, klass, obj) return true if obj.kind_of?(klass) message = "Parameter #{parameter_name} must be instance of #{klass.name}, not #{obj.inspect}" raise TypeError.new(message) end def self.verify_integer_in_range(parameter_name, range, obj) self.verify_kind_of(parameter_name, Integer, obj) return true if range.include?(obj) message = "Parameter #{parameter_name} must be in range #{range}, not #{obj}" raise RangeError.new(message) end def self.verify_range_not_empty(parameter_name, range) self.verify_kind_of(parameter_name, Range, range) return if range.first == range.last if range.each.size == 0 message = "Parameter #{parameter_name} must be a non-empty Range, not #{range}" raise ArgumentError.new(message) end end def self.verify_finite_numeric(parameter_name, obj) self.verify_kind_of(parameter_name, Numeric, obj) if obj.kind_of?(Float) unless obj.finite? message = "Parameter #{parameter_name} must be finite, not #{obj}" raise ArgumentError.new(message) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
test_values-0.5.0 | lib/test_values/values_base.rb |
test_values-0.4.0 | lib/test_values/values_base.rb |