Class: Puppet::Pops::Types::POptionalType
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
#type
Class Method Summary
collapse
Instance Method Summary
collapse
#accept, #eql?, #generalize, #hash, #initialize, #resolve
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #name, new_function, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
Methods included from Visitable
#accept
#_ptype
Class Method Details
.register_ptype(loader, ir) ⇒ Object
2975
2976
2977
2978
2979
2980
2981
2982
|
# File 'lib/puppet/pops/types/types.rb', line 2975
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'AnyType',
'type' => {
KEY_TYPE => POptionalType.new(PType::DEFAULT),
KEY_VALUE => nil
}
)
end
|
Instance Method Details
#instance?(o, guard = nil) ⇒ Boolean
2992
2993
2994
|
# File 'lib/puppet/pops/types/types.rb', line 2992
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
2988
2989
2990
|
# File 'lib/puppet/pops/types/types.rb', line 2988
def kind_of_callable?(optional=true, guard = nil)
optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
end
|
#new_function(loader) ⇒ Object
3013
3014
3015
|
# File 'lib/puppet/pops/types/types.rb', line 3013
def new_function(loader)
optional_type.new_function(loader)
end
|
#normalize(guard = nil) ⇒ Object
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
|
# File 'lib/puppet/pops/types/types.rb', line 2996
def normalize(guard = nil)
n = super
if n.type.nil?
n
else
if n.type.is_a?(PNotUndefType)
POptionalType.new(n.type.type).normalize
elsif n.type.assignable?(PUndefType::DEFAULT)
n.type
else
n
end
end
end
|
#optional_type ⇒ Object
2984
2985
2986
|
# File 'lib/puppet/pops/types/types.rb', line 2984
def optional_type
@type
end
|