Sha256: c65c25e75e0f99c12239ca0776502dfb30b5cd43a0529d133c203cebebbf9575
Contents?: true
Size: 738 Bytes
Versions: 11
Compression:
Stored size: 738 Bytes
Contents
# typed: strict module Typed module Coercion class IntegerCoercer < Coercer extend T::Generic Target = type_member { {fixed: Integer} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def used_for_type?(type) type == T::Utils.coerce(Integer) end sig { override.params(type: T::Types::Base, value: Value).returns(Result[Target, CoercionError]) } def coerce(type:, value:) return Failure.new(CoercionError.new("Type must be a Integer.")) unless used_for_type?(type) Success.new(Integer(value)) rescue ArgumentError, TypeError Failure.new(CoercionError.new("'#{value}' cannot be coerced into Integer.")) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems