Class: Puppet::Pops::Types::PCallableType

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

Constant Summary collapse

DEFAULT =
PCallableType.new(nil)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#assignable?, #callable?, #enumerable?, #simple_name, #to_s

Methods included from Visitable

#accept

Constructor Details

#initialize(param_types, block_type = nil) ⇒ PCallableType

Returns a new instance of PCallableType.

Parameters:



1081
1082
1083
1084
# File 'lib/puppet/pops/types/types.rb', line 1081

def initialize(param_types, block_type = nil)
  @param_types = param_types
  @block_type = block_type
end

Instance Attribute Details

#block_typePAnyType|nil (readonly)

Although being an abstract type reference, only Callable, or all Callables wrapped in Optional or Variant are supported If not set, the meaning is that block is not supported.

Returns:



1077
1078
1079
# File 'lib/puppet/pops/types/types.rb', line 1077

def block_type
  @block_type
end

#param_typesPTupleType (readonly)

Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count

Returns:

  • (PTupleType)

    the tuple representing the parameter types



1071
1072
1073
# File 'lib/puppet/pops/types/types.rb', line 1071

def param_types
  @param_types
end

Instance Method Details

#==(o) ⇒ Object



1135
1136
1137
# File 'lib/puppet/pops/types/types.rb', line 1135

def ==(o)
  self.class == o.class && @param_types == o.param_types && @block_type == o.block_type
end

#block_rangeObject

Range [0,0], [0,1], or [1,1] for the block



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/puppet/pops/types/types.rb', line 1120

def block_range
  case block_type
  when POptionalType
    [0,1]
  when PVariantType, PCallableType
    [1,1]
  else
    [0,0]
  end
end

#callable_args?(required_callable_t) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


1098
1099
1100
1101
# File 'lib/puppet/pops/types/types.rb', line 1098

def callable_args?(required_callable_t)
  # If the required callable is euqal or more specific than self, self is acceptable arguments
  required_callable_t.assignable?(self)
end

#generalizeObject



1086
1087
1088
1089
1090
1091
# File 'lib/puppet/pops/types/types.rb', line 1086

def generalize
  return self if self == DEFAULT
  params_t = @param_types.nil? ? nil : @param_types.generalize
  block_t = @block_type.nil? ? nil : @block_type.generalize
  PCallableType.new(params_t, block_t)
end

#hashObject



1131
1132
1133
# File 'lib/puppet/pops/types/types.rb', line 1131

def hash
  @param_types.hash * 31 + @block_type.hash
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


1093
1094
1095
# File 'lib/puppet/pops/types/types.rb', line 1093

def instance?(o)
  assignable?(TypeCalculator.infer(o))
end

#kind_of_callable?(optional = true) ⇒ Boolean

Returns:

  • (Boolean)


1103
1104
1105
# File 'lib/puppet/pops/types/types.rb', line 1103

def kind_of_callable?(optional=true)
    true
end

#last_rangeObject

Returns the number of accepted arguments for the last parameter type [min, max]



1114
1115
1116
# File 'lib/puppet/pops/types/types.rb', line 1114

def last_range
  @param_types.nil? ? nil : @param_types.repeat_last_range
end

#size_rangeObject

Returns the number of accepted arguments [min, max]



1108
1109
1110
# File 'lib/puppet/pops/types/types.rb', line 1108

def size_range
  @param_types.nil? ? nil : @param_types.size_range
end