Represents an object type
Finalize by setting up a primitive constraint
@return [Class<Axiom::Types::Object>]
@api private
# File lib/axiom/types/object.rb, line 33 def self.finalize return self if frozen? inherits_from_primitive super end
Infer the type of the object
@example
Axiom::Types::Object.infer(::Object) # => Axiom::Types::Object
@param [Object] object
@return [Class<Axiom::Types::Object>]
returned if the type matches
@return [nil]
returned if the type does not match
@api public
# File lib/axiom/types/object.rb, line 24 def self.infer(object) super || infer_from_primitive_class(object) end
Infer the type if the primitive class matches
@param [Object] object
@return [Class<Axiom::Types::Object>]
returned if the primitive class matches
@return [nil]
returned if the primitive class does not match
@api private
# File lib/axiom/types/object.rb, line 49 def self.infer_from_primitive_class(object) self if match_primitive?(object) end
Add a constraint for the primitive
@return [undefined]
@api private
# File lib/axiom/types/object.rb, line 72 def self.inherits_from_primitive constraint(&primitive.method(:===)) end
Test if the type matches a primitive class
@param [Object] object
@return [Boolean]
@api private
# File lib/axiom/types/object.rb, line 61 def self.match_primitive?(object) Module === object && (equal?(Object) || object.ancestors.include?(primitive)) end