Class: Puppet::Pops::Evaluator::CallableSignature
- Defined in:
- lib/puppet/pops/evaluator/callable_signature.rb
Overview
CallableSignature
A CallableSignature describes how something callable expects to be called. Different implementation of this class are used for different types of callables.
Direct Known Subclasses
Instance Method Summary collapse
-
#args_range ⇒ Array[Integer, Numeric]
Returns the range of required/optional argument values as an array of [min, max], where an infinite end is given as Float::INFINITY.
-
#argument_mismatch_handler? ⇒ Boolean
private
True if this signature represents an argument mismatch, false otherwise.
-
#block_name ⇒ String
Returns the name of the block parameter if the callable accepts a block.
-
#block_range ⇒ Array(Integer, Integer)
Returns a range indicating the optionality of a block.
-
#block_type ⇒ Puppet::Pops::Types::PAnyType?
Returns the expected type for an optional block.
-
#infinity?(x) ⇒ Boolean
Returns true if the given x is infinity.
-
#last_captures_rest? ⇒ Boolean
Returns true if the last parameter captures the rest of the arguments, with a possible cap, as indicated by the ‘args_range` method.
-
#parameter_names ⇒ Array<String>
Returns the names of the parameters as an array of strings.
-
#type ⇒ Puppet::Pops::Types::PCallableType
Returns a PCallableType with the type information, required and optional count, and type information about an optional block.
Instance Method Details
#args_range ⇒ Array[Integer, Numeric]
Returns the range of required/optional argument values as an array of [min, max], where an infinite end is given as Float::INFINITY. To test against infinity, use the infinity? method.
78 79 80 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 78 def args_range type.size_range end |
#argument_mismatch_handler? ⇒ 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 true if this signature represents an argument mismatch, false otherwise.
105 106 107 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 105 def argument_mismatch_handler? false end |
#block_name ⇒ String
Returns the name of the block parameter if the callable accepts a block. A derived class must implement this method.
58 59 60 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 58 def block_name raise NotImplementedError end |
#block_range ⇒ Array(Integer, Integer)
Returns a range indicating the optionality of a block. One of [0,0] (does not accept block), [0,1] (optional block), and [1,1] (block required)
67 68 69 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 67 def block_range type.block_range end |
#block_type ⇒ Puppet::Pops::Types::PAnyType?
Returns the expected type for an optional block. The type may be nil, which means that the callable does not accept a block. If a type is returned it is one of Callable, Optional, Variant, or Optional[Variant[Callable, …]]. The Variant type is used when multiple signatures are acceptable. The Optional type is used when the block is optional.
49 50 51 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 49 def block_type type.block_type end |
#infinity?(x) ⇒ Boolean
Returns true if the given x is infinity
98 99 100 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 98 def infinity?(x) x == Float::INFINITY end |
#last_captures_rest? ⇒ Boolean
Returns true if the last parameter captures the rest of the arguments, with a possible cap, as indicated by the ‘args_range` method. A derived class must implement this method.
89 90 91 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 89 def last_captures_rest? raise NotImplementedError end |
#parameter_names ⇒ Array<String>
Returns the names of the parameters as an array of strings. This does not include the name of an optional block parameter.
All implementations are not required to supply names for parameters. They may be used if present, to provide user feedback in errors etc. but they are not authoritative about the number of required arguments, optional arguments, etc.
A derived class must implement this method.
24 25 26 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 24 def parameter_names raise NotImplementedError end |
#type ⇒ Puppet::Pops::Types::PCallableType
Returns a PCallableType with the type information, required and optional count, and type information about an optional block.
A derived class must implement this method.
36 37 38 |
# File 'lib/puppet/pops/evaluator/callable_signature.rb', line 36 def type raise NotImplementedError end |