Class: Puppet::Pops::Types::POptionalType

Inherits:
PAnyType show all
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 collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#assignable?, #callable?, #callable_args?, #enumerable?, #simple_name, #to_s

Methods included from Visitable

#accept

Constructor Details

#initialize(optional_type) ⇒ POptionalType

Returns a new instance of POptionalType.



1513
1514
1515
# File 'lib/puppet/pops/types/types.rb', line 1513

def initialize(optional_type)
  @optional_type = optional_type
end

Instance Attribute Details

#optional_typeObject (readonly)



1511
1512
1513
# File 'lib/puppet/pops/types/types.rb', line 1511

def optional_type
  @optional_type
end

Instance Method Details

#==(o) ⇒ Object



1529
1530
1531
# File 'lib/puppet/pops/types/types.rb', line 1529

def ==(o)
  self.class == o.class && @optional_type == o.optional_type
end

#generalizeObject



1517
1518
1519
# File 'lib/puppet/pops/types/types.rb', line 1517

def generalize
  @optional_type.nil? ? self : PType.new(@optional_type.generalize)
end

#hashObject



1521
1522
1523
# File 'lib/puppet/pops/types/types.rb', line 1521

def hash
  7 * @optional_type.hash
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


1533
1534
1535
# File 'lib/puppet/pops/types/types.rb', line 1533

def instance?(o)
  PUndefType::DEFAULT.instance?(o) || (!optional_type.nil? && optional_type.instance?(o))
end

#kind_of_callable?(optional = true) ⇒ Boolean

Returns:

  • (Boolean)


1525
1526
1527
# File 'lib/puppet/pops/types/types.rb', line 1525

def kind_of_callable?(optional=true)
    optional && !@optional_type.nil? && @optional_type.kind_of_callable?(optional)
end