Class: Puppet::Pops::Types::PEnumType

Inherits:
PScalarType show all
Includes:
Enumerable
Defined in:
lib/puppet/pops/types/types.rb

Overview

A string type describing the set of strings having one of the given values

Constant Summary collapse

DEFAULT =
PEnumType.new([])

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PScalarType

#instance?

Methods inherited from PAnyType

#assignable?, #callable?, #callable_args?, #enumerable?, #generalize, #instance?, #kind_of_callable?, #simple_name, #to_s

Methods included from Visitable

#accept

Constructor Details

#initialize(values) ⇒ PEnumType

Returns a new instance of PEnumType.



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

def initialize(values)
  @values = values.sort.freeze
end

Instance Attribute Details

#valuesObject (readonly)



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

def values
  @values
end

Instance Method Details

#==(o) ⇒ Object



393
394
395
# File 'lib/puppet/pops/types/types.rb', line 393

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

#eachObject

Returns Enumerator if no block is given, otherwise, calls the given block with each of the strings for this enum



381
382
383
384
385
386
387
# File 'lib/puppet/pops/types/types.rb', line 381

def each
  if block_given?
    values.each { |x| yield x }
  else
    values.to_enum
  end
end

#hashObject



389
390
391
# File 'lib/puppet/pops/types/types.rb', line 389

def hash
  @values.hash
end