Class: RBS::Trace::Declaration
- Inherits:
-
Object
- Object
- RBS::Trace::Declaration
- Defined in:
- lib/rbs/trace/declaration.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
: Array.
-
#return_type ⇒ Object
: Array.
-
#void ⇒ Object
readonly
: bool.
Instance Method Summary collapse
-
#initialize(parameters, void: false) ⇒ Declaration
constructor
A new instance of Declaration.
- #merge(other) ⇒ Object
- #to_rbs ⇒ Object
Constructor Details
#initialize(parameters, void: false) ⇒ Declaration
Returns a new instance of Declaration.
14 15 16 17 |
# File 'lib/rbs/trace/declaration.rb', line 14 def initialize(parameters, void: false) @parameters = parameters @void = void end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
: Array
9 10 11 |
# File 'lib/rbs/trace/declaration.rb', line 9 def parameters @parameters end |
#return_type ⇒ Object
: Array
11 12 13 |
# File 'lib/rbs/trace/declaration.rb', line 11 def return_type @return_type end |
#void ⇒ Object (readonly)
: bool
10 11 12 |
# File 'lib/rbs/trace/declaration.rb', line 10 def void @void end |
Instance Method Details
#merge(other) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbs/trace/declaration.rb', line 27 def merge(other) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength new_parameters = @parameters.map.with_index do |parameter, index| kind = parameter[0] name = parameter[1] klass = parameter[2] other_klass = other.parameters[index][2] merged_klass = (klass + other_klass).uniq [kind, name, merged_klass] end Declaration.new(new_parameters, void: void && other.void).tap do |decl| decl.return_type = (return_type + other.return_type).uniq end end |
#to_rbs ⇒ Object
20 21 22 23 24 |
# File 'lib/rbs/trace/declaration.rb', line 20 def to_rbs return_rbs = void ? "void" : convert_type(return_type) "(#{parameters_rbs}) -> #{return_rbs}" end |