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
Class Method Summary collapse
Instance Method Summary collapse
- #instance?(o, guard = nil) ⇒ Boolean
- #kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
- #new_function(loader) ⇒ Object
- #normalize(guard = nil) ⇒ Object
- #optional_type ⇒ Object
Methods inherited from PTypeWithContainedType
#accept, #eql?, #generalize, #hash, #initialize, #resolve
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #eql?, #generalize, #hash, #iterable?, #iterable_type, #name, new_function, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s
Methods inherited from TypedModelObject
_ptype, create_ptype, register_ptypes
Methods included from Visitable
Methods included from PuppetObject
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PTypeWithContainedType
Class Method Details
Instance Method Details
#instance?(o, guard = nil) ⇒ Boolean
2902 2903 2904 |
# File 'lib/puppet/pops/types/types.rb', line 2902 def instance?(o, guard = nil) PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard)) end |
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
2898 2899 2900 |
# File 'lib/puppet/pops/types/types.rb', line 2898 def kind_of_callable?(optional=true, guard = nil) optional && !@type.nil? && @type.kind_of_callable?(optional, guard) end |
#new_function(loader) ⇒ Object
2923 2924 2925 |
# File 'lib/puppet/pops/types/types.rb', line 2923 def new_function(loader) optional_type.new_function(loader) end |
#normalize(guard = nil) ⇒ Object
2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 |
# File 'lib/puppet/pops/types/types.rb', line 2906 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
2894 2895 2896 |
# File 'lib/puppet/pops/types/types.rb', line 2894 def optional_type @type end |