Class: Puppet::Pops::Types::PCollectionType
Constant Summary
collapse
- DEFAULT_SIZE =
PIntegerType.new(0)
- ZERO_SIZE =
PIntegerType.new(0, 0)
- DEFAULT =
PCollectionType.new(nil)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_args?, #kind_of_callable?, #simple_name, #to_alias_expanded_s, #to_s
Constructor Details
#initialize(element_type, size_type = nil) ⇒ PCollectionType
Returns a new instance of PCollectionType.
783
784
785
786
|
# File 'lib/puppet/pops/types/types.rb', line 783
def initialize(element_type, size_type = nil)
@element_type = element_type
@size_type = size_type
end
|
Instance Attribute Details
#element_type ⇒ Object
781
782
783
|
# File 'lib/puppet/pops/types/types.rb', line 781
def element_type
@element_type
end
|
#size_type ⇒ Object
781
782
783
|
# File 'lib/puppet/pops/types/types.rb', line 781
def size_type
@size_type
end
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
788
789
790
791
792
|
# File 'lib/puppet/pops/types/types.rb', line 788
def accept(visitor, guard)
super
@size_type.accept(visitor, guard) unless @size_type.nil?
@element_type.accept(visitor, guard) unless @element_type.nil?
end
|
#eql?(o) ⇒ Boolean
833
834
835
|
# File 'lib/puppet/pops/types/types.rb', line 833
def eql?(o)
self.class == o.class && @element_type == o.element_type && @size_type == o.size_type
end
|
#generalize ⇒ Object
794
795
796
797
798
799
800
801
|
# File 'lib/puppet/pops/types/types.rb', line 794
def generalize
if @element_type.nil?
DEFAULT
else
ge_type = @element_type.generalize
@size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
end
end
|
821
822
823
|
# File 'lib/puppet/pops/types/types.rb', line 821
def hash
@element_type.hash ^ @size_type.hash
end
|
#instance?(o) ⇒ Boolean
812
813
814
|
# File 'lib/puppet/pops/types/types.rb', line 812
def instance?(o)
assignable?(TypeCalculator.infer(o))
end
|
#iterable?(guard = nil) ⇒ Boolean
825
826
827
|
# File 'lib/puppet/pops/types/types.rb', line 825
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
829
830
831
|
# File 'lib/puppet/pops/types/types.rb', line 829
def iterable_type(guard = nil)
@element_type.nil? ? PIterableType::DEFAULT : PIterableType.new(@element_type)
end
|
#normalize(guard = nil) ⇒ Object
803
804
805
806
807
808
809
810
|
# File 'lib/puppet/pops/types/types.rb', line 803
def normalize(guard = nil)
if @element_type.nil?
DEFAULT
else
ne_type = @element_type.normalize(guard)
@element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
end
end
|
#size_range ⇒ Object
Returns an array with from (min) size to (max) size
817
818
819
|
# File 'lib/puppet/pops/types/types.rb', line 817
def size_range
(@size_type || DEFAULT_SIZE).range
end
|