Class: Puppet::Pops::Types::PAnyType
- Inherits:
-
TypedModelObject
- Object
- TypedModelObject
- Puppet::Pops::Types::PAnyType
- Defined in:
- lib/puppet/pops/types/types.rb
Overview
Base type for all types
Direct Known Subclasses
PCallableType, PCatalogEntryType, PCollectionType, PDataType, PDefaultType, PNotUndefType, POptionalType, PRuntimeType, PScalarType, PStructType, PTupleType, PType, PUndefType, PUnitType, PVariantType
Constant Summary collapse
- DEFAULT =
The default instance of this type. Each type in the type system has this constant declared.
PAnyType.new
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
-
#assignable?(o) ⇒ Boolean
Checks if o is a type that is assignable to this type.
-
#callable?(args) ⇒ Boolean
Returns ‘true` if this instance is a callable that accepts the given args.
-
#callable_args?(callable) ⇒ Boolean
private
Returns ‘true` if this instance is considered valid as arguments to callable.
-
#enumerable? ⇒ Boolean
Subclasses that are enumerable will override this method to return ‘true`.
-
#generalize ⇒ PAnyType
Generalizes value specific types.
- #hash ⇒ Object
-
#instance?(o) ⇒ Boolean
Returns true if the given argument o is an instance of this type.
-
#kind_of_callable?(optional = true) ⇒ Boolean
private
Responds ‘true` for all callables, variants of callables and unless optional is false, all optional callables.
-
#simple_name ⇒ String
Strips the class name from all module prefixes, the leading ‘P’ and the ending ‘Type’.
- #to_s ⇒ Object
Methods included from Visitable
Instance Method Details
#==(o) ⇒ Object Also known as: eql?
103 104 105 |
# File 'lib/puppet/pops/types/types.rb', line 103 def ==(o) self.class == o.class end |
#assignable?(o) ⇒ Boolean
Checks if o is a type that is assignable to this type. If o is a ‘Class` then it is first converted to a type. If o is a Variant, then it is considered assignable when all its types are assignable
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet/pops/types/types.rb', line 34 def assignable?(o) case o when Class # Safe to call _assignable directly since a Class never is a Unit or Variant _assignable?(Puppet::Pops::Types::TypeCalculator.singleton.type(o)) when PUnitType true when PVariantType # Assignable if all contained types are assignable o.types.all? { |vt| assignable?(vt) } when PNotUndefType if !(o.type.nil? || o.type.assignable?(PUndefType::DEFAULT)) assignable?(o.type) else _assignable?(o) end else _assignable?(o) end end |
#callable?(args) ⇒ Boolean
Returns ‘true` if this instance is a callable that accepts the given args
58 59 60 |
# File 'lib/puppet/pops/types/types.rb', line 58 def callable?(args) args.is_a?(PAnyType) && kind_of_callable? && args.callable_args?(self) end |
#callable_args?(callable) ⇒ Boolean
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.
Returns ‘true` if this instance is considered valid as arguments to callable
65 66 67 |
# File 'lib/puppet/pops/types/types.rb', line 65 def callable_args?(callable) false end |
#enumerable? ⇒ Boolean
Subclasses that are enumerable will override this method to return ‘true`
71 72 73 |
# File 'lib/puppet/pops/types/types.rb', line 71 def enumerable? is_a?(Enumerable) end |
#generalize ⇒ PAnyType
Generalizes value specific types. Types that are not value specific will return ‘self` otherwize the generalized type is returned.
80 81 82 83 |
# File 'lib/puppet/pops/types/types.rb', line 80 def generalize # Applicable to all types that have no variables self end |
#hash ⇒ Object
93 94 95 |
# File 'lib/puppet/pops/types/types.rb', line 93 def hash self.class.hash end |
#instance?(o) ⇒ Boolean
Returns true if the given argument o is an instance of this type
99 100 101 |
# File 'lib/puppet/pops/types/types.rb', line 99 def instance?(o) true end |
#kind_of_callable?(optional = true) ⇒ Boolean
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.
Responds ‘true` for all callables, variants of callables and unless optional is false, all optional callables.
89 90 91 |
# File 'lib/puppet/pops/types/types.rb', line 89 def kind_of_callable?(optional=true) false end |
#simple_name ⇒ String
Strips the class name from all module prefixes, the leading ‘P’ and the ending ‘Type’. I.e. an instance of Puppet::Pops::Types::PVariantType will return ‘Variant’
112 113 114 115 |
# File 'lib/puppet/pops/types/types.rb', line 112 def simple_name n = self.class.name n[n.rindex('::')+3..n.size-5] end |