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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PTypeWithContainedType

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

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #generalize, #hash, #kind_of_callable?, #name, #new_function, new_function, #normalize, #really_instance?, #resolve, #simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_ptype, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_ptype

Constructor Details

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

Class Method Details

.register_ptype(loader, ir) ⇒ Object



425
426
427
428
429
430
431
432
# File 'lib/puppet/pops/types/types.rb', line 425

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType',
     'type' => {
       KEY_TYPE => POptionalType.new(PType::DEFAULT),
       KEY_VALUE => nil
     }
  )
end

.simple_nameObject



473
474
475
476
# File 'lib/puppet/pops/types/types.rb', line 473

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

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


469
470
471
# File 'lib/puppet/pops/types/types.rb', line 469

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

#instance?(o, guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


434
435
436
437
438
439
440
# File 'lib/puppet/pops/types/types.rb', line 434

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

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


442
443
444
445
446
447
448
449
450
451
# File 'lib/puppet/pops/types/types.rb', line 442

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

#iterable_type(guard = nil) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/puppet/pops/types/types.rb', line 453

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