Class: Axiom::Types::Type
- Inherits:
-
Object
- Object
- Axiom::Types::Type
- Extended by:
- Options, DescendantsTracker
- Defined in:
- lib/axiom/types/type.rb
Overview
Abstract base class for every type
Direct Known Subclasses
Class Method Summary collapse
-
.anonymous? ⇒ Boolean
Test if the type is anonymous.
-
.base ⇒ Class<Axiom::Types::Type>
The base type for the type.
-
.base? ⇒ Boolean
Test if the type is a base type.
-
.constraint(constraint = Undefined) {|object| ... } ⇒ Class<Axiom::Types::Type>
Add a constraint to the type.
-
.finalize ⇒ Class<Axiom::Types::Type>
private
Finalize by deep freezing.
-
.include?(object) ⇒ Boolean
Test if the object matches the type constraint.
-
.includes(*members) ⇒ undefined
private
Add a constraint that the object must be included in a set.
-
.infer(object) ⇒ Class<Axiom::Types::Type>
Infer the type of the object.
-
.new(*args) {|object| ... } ⇒ Class<Axiom::Types::Type>
Instantiate a new Axiom::Types::Type subclass.
Methods included from Options
Class Method Details
.anonymous? ⇒ Boolean
Test if the type is anonymous
157 158 159 |
# File 'lib/axiom/types/type.rb', line 157 def self.anonymous? name.to_s.empty? end |
.base ⇒ Class<Axiom::Types::Type>
The base type for the type
139 140 141 |
# File 'lib/axiom/types/type.rb', line 139 def self.base base? ? self : superclass.base end |
.base? ⇒ Boolean
Test if the type is a base type
148 149 150 |
# File 'lib/axiom/types/type.rb', line 148 def self.base? !anonymous? end |
.constraint(constraint = Undefined) {|object| ... } ⇒ Class<Axiom::Types::Type>
Add a constraint to the type
113 114 115 116 117 118 |
# File 'lib/axiom/types/type.rb', line 113 def self.constraint(constraint = Undefined, &block) constraint = block if constraint.equal?(Undefined) return @constraint if constraint.nil? add_constraint(constraint) self end |
.finalize ⇒ Class<Axiom::Types::Type>
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 deep freezing
58 59 60 61 |
# File 'lib/axiom/types/type.rb', line 58 def self.finalize IceNine.deep_freeze(constraint) freeze end |
.include?(object) ⇒ Boolean
Test if the object matches the type constraint
81 82 83 |
# File 'lib/axiom/types/type.rb', line 81 def self.include?(object) constraint.call(object) end |
.includes(*members) ⇒ undefined
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.
move into a module
Add a constraint that the object must be included in a set
129 130 131 132 |
# File 'lib/axiom/types/type.rb', line 129 def self.includes(*members) set = IceNine.deep_freeze(members.to_set) constraint(&set.method(:include?)) end |
.infer(object) ⇒ Class<Axiom::Types::Type>
Infer the type of the object
24 25 26 |
# File 'lib/axiom/types/type.rb', line 24 def self.infer(object) self if equal?(object) end |
.new(*args) {|object| ... } ⇒ Class<Axiom::Types::Type>
Instantiate a new Axiom::Types::Type subclass
47 48 49 50 51 |
# File 'lib/axiom/types/type.rb', line 47 def self.new(*args, &block) type = ::Class.new(self, &block) type.constraint(*args) type.finalize end |