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
- #accept(visitor, guard) ⇒ Object
-
#block_range ⇒ Object
Range [0,0], [0,1], or [1,1] for the block.
- #callable_args?(required_callable_t, guard) ⇒ Boolean private
- #eql?(o) ⇒ Boolean
- #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, guard = nil) ⇒ Boolean
-
#last_range ⇒ Object
Returns the number of accepted arguments for the last parameter type [min, max].
- #normalize(guard = nil) ⇒ Object
-
#size_range ⇒ Object
Returns the number of accepted arguments [min, max].
Methods inherited from PAnyType
#==, #assignable?, #callable?, #iterable?, #iterable_type, #simple_name, #to_alias_expanded_s, #to_s
Constructor Details
#initialize(param_types, block_type = nil) ⇒ PCallableType
Returns a new instance of PCallableType.
1503 1504 1505 1506 |
# File 'lib/puppet/pops/types/types.rb', line 1503 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.
1499 1500 1501 |
# File 'lib/puppet/pops/types/types.rb', line 1499 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
1493 1494 1495 |
# File 'lib/puppet/pops/types/types.rb', line 1493 def param_types @param_types end |
Instance Method Details
#accept(visitor, guard) ⇒ Object
1508 1509 1510 1511 1512 |
# File 'lib/puppet/pops/types/types.rb', line 1508 def accept(visitor, guard) super @param_types.accept(visitor, guard) unless @param_types.nil? @block_type.accept(visitor, guard) unless @block_type.nil? end |
#block_range ⇒ Object
Range [0,0], [0,1], or [1,1] for the block
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 |
# File 'lib/puppet/pops/types/types.rb', line 1561 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, guard) ⇒ 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.
1539 1540 1541 1542 |
# File 'lib/puppet/pops/types/types.rb', line 1539 def callable_args?(required_callable_t, guard) # If the required callable is euqal or more specific than self, self is acceptable arguments required_callable_t.assignable?(self, guard) end |
#eql?(o) ⇒ Boolean
1576 1577 1578 |
# File 'lib/puppet/pops/types/types.rb', line 1576 def eql?(o) self.class == o.class && @param_types == o.param_types && @block_type == o.block_type end |
#generalize ⇒ Object
1514 1515 1516 1517 1518 1519 1520 1521 1522 |
# File 'lib/puppet/pops/types/types.rb', line 1514 def generalize if self == DEFAULT DEFAULT else params_t = @param_types.nil? ? nil : @param_types.generalize block_t = @block_type.nil? ? nil : @block_type.generalize @param_types.equal?(params_t) && @block_type.equal?(block_t) ? self : PCallableType.new(params_t, block_t) end end |
#hash ⇒ Object
1572 1573 1574 |
# File 'lib/puppet/pops/types/types.rb', line 1572 def hash @param_types.hash ^ @block_type.hash end |
#instance?(o) ⇒ Boolean
1534 1535 1536 |
# File 'lib/puppet/pops/types/types.rb', line 1534 def instance?(o) assignable?(TypeCalculator.infer(o)) end |
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
1544 1545 1546 |
# File 'lib/puppet/pops/types/types.rb', line 1544 def kind_of_callable?(optional=true, guard = nil) true end |
#last_range ⇒ Object
Returns the number of accepted arguments for the last parameter type [min, max]
1555 1556 1557 |
# File 'lib/puppet/pops/types/types.rb', line 1555 def last_range @param_types.nil? ? nil : @param_types.repeat_last_range end |
#normalize(guard = nil) ⇒ Object
1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'lib/puppet/pops/types/types.rb', line 1524 def normalize(guard = nil) if self == DEFAULT DEFAULT else params_t = @param_types.nil? ? nil : @param_types.normalize(guard) block_t = @block_type.nil? ? nil : @block_type.normalize(guard) @param_types.equal?(params_t) && @block_type.equal?(block_t) ? self : PCallableType.new(params_t, block_t) end end |
#size_range ⇒ Object
Returns the number of accepted arguments [min, max]
1549 1550 1551 |
# File 'lib/puppet/pops/types/types.rb', line 1549 def size_range @param_types.nil? ? nil : @param_types.size_range end |