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
3246 def self.register_ptype(loader, ir)
3247   create_ptype(loader, ir, 'AnyType',
3248     'type' => {
3249       KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3250       KEY_VALUE => nil
3251     }
3252   )
3253 end

Public Instance Methods

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

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

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