Class: Puppet::Pops::Types::PArrayType

Inherits:
PCollectionType show all
Defined in:
lib/puppet/pops/types/types.rb

Constant Summary collapse

DATA =
PArrayType.new(PDataType::DEFAULT, PCollectionType::DEFAULT_SIZE)
DEFAULT =
PArrayType.new(nil)
EMPTY =
PArrayType.new(PUnitType::DEFAULT, PCollectionType::ZERO_SIZE)

Constants inherited from PCollectionType

Puppet::Pops::Types::PCollectionType::DEFAULT_SIZE, Puppet::Pops::Types::PCollectionType::ZERO_SIZE

Instance Attribute Summary

Attributes inherited from PCollectionType

#element_type, #size_type

Instance Method Summary collapse

Methods inherited from PCollectionType

#==, #hash, #initialize, #size_range

Methods inherited from PAnyType

#==, #assignable?, #callable?, #enumerable?, #hash, #kind_of_callable?, #simple_name, #to_s

Methods included from Visitable

#accept

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::PCollectionType

Instance Method Details

#callable_args?(callable) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


1165
1166
1167
1168
1169
1170
# File 'lib/puppet/pops/types/types.rb', line 1165

def callable_args?(callable)
  param_t = callable.param_types
  block_t = callable.block_type
  # does not support calling with a block, but have to check that callable is ok with missing block
  (param_t.nil? || param_t.assignable?(self)) && (block_t.nil? || block_t.assignable(PUndefType::DEFAULT))
end

#generalizeObject



1172
1173
1174
1175
1176
1177
1178
# File 'lib/puppet/pops/types/types.rb', line 1172

def generalize
  if self == DEFAULT
    self
  else
    PArrayType.new(element_type.nil? ? nil : element_type.generalize)
  end
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


1180
1181
1182
1183
1184
1185
1186
# File 'lib/puppet/pops/types/types.rb', line 1180

def instance?(o)
  return false unless o.is_a?(Array)
  element_t = element_type
  return false unless element_t.nil? || o.all? {|element| element_t.instance?(element) }
  size_t = size_type
  size_t.nil? || size_t.instance?(o.size)
end