Class: Axiom::Types::Collection

Inherits:
Object show all
Defined in:
lib/axiom/types/collection.rb

Overview

Represents a collection type

Direct Known Subclasses

Array, Set

Class Method Summary collapse

Methods inherited from Type

constraint, include?, includes, new

Methods included from Options

#accept_options

Class Method Details

.finalizeClass<Axiom::Types::Collection>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finalize by setting up constraints for the member



57
58
59
60
61
62
# File 'lib/axiom/types/collection.rb', line 57

def self.finalize
  return self if frozen?
  member_type.finalize
  matches_member_type
  super
end

.infer(object) ⇒ Class<Axiom::Types::Collection>?

Infer the type of the object

Examples:

with a type

Axiom::Types::Array.infer(Axiom::Types::Array)
# => Axiom::Types::Array

with a primitive class

Axiom::Types::Collection.infer(::Array)
# => Axiom::Types::Array

with a primitive instance

Axiom::Types::Array.infer(Array[])
# => Axiom::Types::Array

with a primitive instance and a member type

Axiom::Types::Collection.infer(Array[Axiom::Types::String])
# => Axiom::Types::Array subclass w/String member type

with a primitive instance and a member primitive

Axiom::Types::Collection.infer(Array[String])
# => Axiom::Types::Array subclass w/String member type

Parameters:

Returns:



43
44
45
46
47
48
49
50
# File 'lib/axiom/types/collection.rb', line 43

def self.infer(object)
  case object
  when primitive
    infer_from_primitive_instance(object)
  else
    super
  end
end