Class: Dialekt::Util::CallSignature
- Inherits:
-
Object
- Object
- Dialekt::Util::CallSignature
- Defined in:
- lib/dialekt/util/call_signature.rb
Overview
Call signature information for Proc objects
Defined Under Namespace
Classes: Parameter
Instance Attribute Summary collapse
-
#extra_options ⇒ Object
readonly
Returns the value of attribute extra_options.
-
#extra_parameters ⇒ Object
readonly
Returns the value of attribute extra_parameters.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parameters:, extra_parameters:, options:, extra_options:) ⇒ CallSignature
constructor
A new instance of CallSignature.
- #optional_parameter_count ⇒ Object
- #required_parameter_count ⇒ Object
Constructor Details
#initialize(parameters:, extra_parameters:, options:, extra_options:) ⇒ CallSignature
Returns a new instance of CallSignature.
53 54 55 56 57 58 |
# File 'lib/dialekt/util/call_signature.rb', line 53 def initialize(parameters:, extra_parameters:, options:, extra_options:) @parameters = parameters.dup.freeze @extra_parameters = extra_parameters @options = .dup.freeze @extra_options = end |
Instance Attribute Details
#extra_options ⇒ Object (readonly)
Returns the value of attribute extra_options.
51 52 53 |
# File 'lib/dialekt/util/call_signature.rb', line 51 def @extra_options end |
#extra_parameters ⇒ Object (readonly)
Returns the value of attribute extra_parameters.
51 52 53 |
# File 'lib/dialekt/util/call_signature.rb', line 51 def extra_parameters @extra_parameters end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
51 52 53 |
# File 'lib/dialekt/util/call_signature.rb', line 51 def @options end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
51 52 53 |
# File 'lib/dialekt/util/call_signature.rb', line 51 def parameters @parameters end |
Class Method Details
.create(signature:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dialekt/util/call_signature.rb', line 26 def create(signature:) parameters = [] = {} extra_parameters = nil = nil signature.each do |type, name| case type when :req, :opt parameters << Parameter.new(name: name, optional: type == :opt) when :rest extra_parameters = Parameter.new(name: name, optional: true) when :keyreq, :key [name] = Parameter.new(name: name, optional: type == :key) when :keyrest = Parameter.new(name: name, optional: true) else raise ArgumentError, "Illegal type #{type} in signature #{PP.singleline_pp(signature, StringIO.new).string}" end end new(parameters: parameters, extra_parameters: extra_parameters, options: , extra_options: ) end |
Instance Method Details
#optional_parameter_count ⇒ Object
64 65 66 |
# File 'lib/dialekt/util/call_signature.rb', line 64 def optional_parameter_count @optional_parameter_count ||= @parameters.count(&:optional?) end |
#required_parameter_count ⇒ Object
60 61 62 |
# File 'lib/dialekt/util/call_signature.rb', line 60 def required_parameter_count @required_parameter_count ||= @parameters.count { |p| !p.optional? } end |