Class: Puppet::Pops::Types::PType

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

Overview

The type of types.

Constant Summary collapse

DEFAULT =
PType.new(nil)

Instance Attribute Summary

Attributes inherited from PTypeWithContainedType

#type

Instance Method Summary collapse

Methods inherited from PTypeWithContainedType

#accept, #generalize, #hash, #initialize, #normalize

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #generalize, #hash, #kind_of_callable?, #normalize, #to_alias_expanded_s, #to_s

Methods included from Visitable

#accept

Constructor Details

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

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


374
375
376
# File 'lib/puppet/pops/types/types.rb', line 374

def eql?(o)
  self.class == o.class && @type == o.type
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


339
340
341
342
343
344
345
# File 'lib/puppet/pops/types/types.rb', line 339

def instance?(o)
  if o.is_a?(PAnyType)
    type.nil? || type.assignable?(o)
  else
    assignable?(TypeCalculator.infer(o))
  end
end

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


347
348
349
350
351
352
353
354
355
356
# File 'lib/puppet/pops/types/types.rb', line 347

def iterable?(guard = nil)
  case @type
  when PEnumType
    true
  when PIntegerType
    @type.finite_range?
  else
    false
  end
end

#iterable_type(guard = nil) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/puppet/pops/types/types.rb', line 358

def iterable_type(guard = nil)
  # The types PIntegerType and PEnumType are Iterable
  case @type
  when PEnumType
    # @type describes the element type perfectly since the iteration is made over the
    # contained choices.
    PIterableType.new(@type)
  when PIntegerType
    # @type describes the element type perfectly since the iteration is made over the
    # specified range.
    @type.finite_range? ? PIterableType.new(@type) : nil
  else
    nil
  end
end

#simple_nameObject



378
379
380
381
# File 'lib/puppet/pops/types/types.rb', line 378

def simple_name
  # since this the class is inconsistently named PType and not PTypeType
  'Type'
end