Class: Puppet::Pops::Types::PCallableType
- Inherits:
-
PAnyType
- Object
- TypedModelObject
- PAnyType
- Puppet::Pops::Types::PCallableType
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary collapse
- DEFAULT =
PCallableType.new(nil)
Instance Attribute Summary collapse
-
#block_type ⇒ PAnyType|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.
-
#param_types ⇒ PTupleType
readonly
Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#block_range ⇒ Object
Range [0,0], [0,1], or [1,1] for the block.
- #callable_args?(required_callable_t) ⇒ Boolean private
- #generalize ⇒ Object
- #hash ⇒ Object
-
#initialize(param_types, block_type = nil) ⇒ PCallableType
constructor
A new instance of PCallableType.
- #instance?(o) ⇒ Boolean
- #kind_of_callable?(optional = true) ⇒ Boolean
-
#last_range ⇒ Object
Returns the number of accepted arguments for the last parameter type [min, max].
-
#size_range ⇒ Object
Returns the number of accepted arguments [min, max].
Methods inherited from PAnyType
#assignable?, #callable?, #enumerable?, #simple_name, #to_s
Methods included from Visitable
Constructor Details
#initialize(param_types, block_type = nil) ⇒ PCallableType
Returns a new instance of PCallableType.
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_type ⇒ PAnyType|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.
1077 1078 1079 |
# File 'lib/puppet/pops/types/types.rb', line 1077 def block_type @block_type end |
#param_types ⇒ PTupleType (readonly)
Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count
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_range ⇒ Object
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.
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 |
#generalize ⇒ Object
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 |
#hash ⇒ Object
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
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
1103 1104 1105 |
# File 'lib/puppet/pops/types/types.rb', line 1103 def kind_of_callable?(optional=true) true end |
#last_range ⇒ Object
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_range ⇒ Object
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 |