class Puppet::Pops::Types::PCollectionType
@api public
Constants
- DEFAULT
- DEFAULT_SIZE
- NOT_EMPTY_SIZE
- ZERO_SIZE
Attributes
size_type[R]
Public Class Methods
new(size_type)
click to toggle source
# File lib/puppet/pops/types/types.rb 1320 def initialize(size_type) 1321 @size_type = size_type.nil? ? nil : size_type.to_size 1322 end
register_ptype(loader, ir)
click to toggle source
# File lib/puppet/pops/types/types.rb 1309 def self.register_ptype(loader, ir) 1310 create_ptype(loader, ir, 'AnyType', 1311 'size_type' => { 1312 KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)), 1313 KEY_VALUE => nil 1314 } 1315 ) 1316 end
Public Instance Methods
accept(visitor, guard)
click to toggle source
Calls superclass method
Puppet::Pops::Types::PAnyType#accept
# File lib/puppet/pops/types/types.rb 1324 def accept(visitor, guard) 1325 super 1326 @size_type.accept(visitor, guard) unless @size_type.nil? 1327 end
eql?(o)
click to toggle source
# File lib/puppet/pops/types/types.rb 1364 def eql?(o) 1365 self.class == o.class && @size_type == o.size_type 1366 end
generalize()
click to toggle source
# File lib/puppet/pops/types/types.rb 1329 def generalize 1330 DEFAULT 1331 end
has_empty_range?()
click to toggle source
# File lib/puppet/pops/types/types.rb 1351 def has_empty_range? 1352 from, to = size_range 1353 from == 0 && to == 0 1354 end
hash()
click to toggle source
# File lib/puppet/pops/types/types.rb 1356 def hash 1357 @size_type.hash 1358 end
instance?(o, guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 1337 def instance?(o, guard = nil) 1338 # The inferred type of a class derived from Array or Hash is either Runtime or Object. It's not assignable to the Collection type. 1339 if o.instance_of?(Array) || o.instance_of?(Hash) 1340 @size_type.nil? || @size_type.instance?(o.size) 1341 else 1342 false 1343 end 1344 end
iterable?(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 1360 def iterable?(guard = nil) 1361 true 1362 end
normalize(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 1333 def normalize(guard = nil) 1334 DEFAULT 1335 end
size_range()
click to toggle source
Returns an array with from (min) size to (max) size
# File lib/puppet/pops/types/types.rb 1347 def size_range 1348 (@size_type || DEFAULT_SIZE).range 1349 end
Protected Instance Methods
_assignable?(o, guard)
click to toggle source
@api private
# File lib/puppet/pops/types/types.rb 1378 def _assignable?(o, guard) 1379 case o 1380 when PCollectionType 1381 (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard) 1382 when PTupleType 1383 # compute the tuple's min/max size, and check if that size matches 1384 size_s = size_type || DEFAULT_SIZE 1385 size_o = o.size_type 1386 if size_o.nil? 1387 type_count = o.types.size 1388 size_o = PIntegerType.new(type_count, type_count) 1389 end 1390 size_s.assignable?(size_o) 1391 when PStructType 1392 from = to = o.elements.size 1393 (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard) 1394 else 1395 false 1396 end 1397 end