class Puppet::Pops::Types::POptionalType

Represents a type that accept PUndefType instead of the type parameter required_type - is a short hand for Variant[T, Undef] @api public

Constants

DEFAULT

Public Class Methods

register_ptype(loader, ir) click to toggle source
     # File lib/puppet/pops/types/types.rb
3245 def self.register_ptype(loader, ir)
3246   create_ptype(loader, ir, 'AnyType',
3247     'type' => {
3248       KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3249       KEY_VALUE => nil
3250     }
3251   )
3252 end

Public Instance Methods

instance?(o, guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
3262 def instance?(o, guard = nil)
3263   PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
3264 end
kind_of_callable?(optional=true, guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
3258 def kind_of_callable?(optional=true, guard = nil)
3259     optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
3260 end
new_function() click to toggle source
     # File lib/puppet/pops/types/types.rb
3283 def new_function
3284   optional_type.new_function
3285 end
normalize(guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
3266 def normalize(guard = nil)
3267   n = super
3268   if n.type.nil?
3269     n
3270   else
3271     if n.type.is_a?(PNotUndefType)
3272       # No point in having an NotUndef in an Optional
3273       POptionalType.new(n.type.type).normalize
3274     elsif n.type.assignable?(PUndefType::DEFAULT)
3275       # THe type is Optional anyway, so it can be stripped of
3276       n.type
3277     else
3278       n
3279     end
3280   end
3281 end
optional_type() click to toggle source
     # File lib/puppet/pops/types/types.rb
3254 def optional_type
3255   @type
3256 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

     # File lib/puppet/pops/types/types.rb
3292 def _assignable?(o, guard)
3293   return true if o.is_a?(PUndefType)
3294   return true if @type.nil?
3295   if o.is_a?(POptionalType)
3296     @type.assignable?(o.optional_type, guard)
3297   else
3298     @type.assignable?(o, guard)
3299   end
3300 end