Class: Puppet::Pops::Types::POptionalType
- Inherits:
-
PTypeWithContainedType
- Object
- TypedModelObject
- PAnyType
- PTypeWithContainedType
- Puppet::Pops::Types::POptionalType
- Defined in:
- lib/puppet/pops/types/types.rb
Overview
Represents a type that accept PUndefType instead of the type parameter required_type - is a short hand for Variant[T, Undef]
Constant Summary collapse
- DEFAULT =
POptionalType.new(nil)
Instance Attribute Summary
Attributes inherited from PTypeWithContainedType
Instance Method Summary collapse
- #instance?(o) ⇒ Boolean
- #kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
- #normalize(guard = nil) ⇒ Object
- #optional_type ⇒ Object
Methods inherited from PTypeWithContainedType
#accept, #eql?, #generalize, #hash, #initialize
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #eql?, #generalize, #hash, #iterable?, #iterable_type, #simple_name, #to_alias_expanded_s, #to_s
Methods included from Visitable
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PTypeWithContainedType
Instance Method Details
#instance?(o) ⇒ Boolean
2161 2162 2163 |
# File 'lib/puppet/pops/types/types.rb', line 2161 def instance?(o) PUndefType::DEFAULT.instance?(o) || (!@type.nil? && @type.instance?(o)) end |
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
2157 2158 2159 |
# File 'lib/puppet/pops/types/types.rb', line 2157 def kind_of_callable?(optional=true, guard = nil) optional && !@type.nil? && @type.kind_of_callable?(optional, guard) end |
#normalize(guard = nil) ⇒ Object
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 |
# File 'lib/puppet/pops/types/types.rb', line 2165 def normalize(guard = nil) n = super if n.type.nil? n else if n.type.is_a?(PNotUndefType) # No point in having an NotUndef in an Optional POptionalType.new(n.type.type).normalize elsif n.type.assignable?(PUndefType::DEFAULT) # THe type is Optional anyway, so it can be stripped of n.type else n end end end |
#optional_type ⇒ Object
2153 2154 2155 |
# File 'lib/puppet/pops/types/types.rb', line 2153 def optional_type @type end |