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

Inherits:
PAnyType 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 collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#assignable?, #callable?, #callable_args?, #enumerable?, #kind_of_callable?, #to_s

Methods included from Visitable

#accept

Constructor Details

#initialize(type) ⇒ PType

Returns a new instance of PType.



186
187
188
# File 'lib/puppet/pops/types/types.rb', line 186

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)



184
185
186
# File 'lib/puppet/pops/types/types.rb', line 184

def type
  @type
end

Instance Method Details

#==(o) ⇒ Object



206
207
208
# File 'lib/puppet/pops/types/types.rb', line 206

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

#generalizeObject



198
199
200
# File 'lib/puppet/pops/types/types.rb', line 198

def generalize
  @type.nil? ? DEFAULT : PType.new(type.generalize)
end

#hashObject



202
203
204
# File 'lib/puppet/pops/types/types.rb', line 202

def hash
  31 * @type.hash
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


190
191
192
193
194
195
196
# File 'lib/puppet/pops/types/types.rb', line 190

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

#simple_nameObject



210
211
212
213
# File 'lib/puppet/pops/types/types.rb', line 210

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