Class: Solargraph::Pin::Closure
Instance Attribute Summary collapse
#node
Instance Method Summary
collapse
Constructor Details
#initialize(scope: :class, generics: nil, generic_defaults: {}, **splat) ⇒ Closure
Returns a new instance of Closure.
13
14
15
16
17
18
|
# File 'lib/solargraph/pin/closure.rb', line 13
def initialize scope: :class, generics: nil, generic_defaults: {}, **splat
super(**splat)
@scope = scope
@generics = generics
@generic_defaults = generic_defaults
end
|
Instance Attribute Details
#scope ⇒ ::Symbol
Returns :class or :instance.
7
8
9
|
# File 'lib/solargraph/pin/closure.rb', line 7
def scope
@scope
end
|
Instance Method Details
#combine_with(other, attrs = {}) ⇒ self
29
30
31
32
33
34
35
|
# File 'lib/solargraph/pin/closure.rb', line 29
def combine_with other, attrs = {}
new_attrs = {
scope: assert_same(other, :scope),
generics: generics.empty? ? other.generics : generics
}.merge(attrs)
super(other, new_attrs)
end
|
#context ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/solargraph/pin/closure.rb', line 37
def context
@context ||= begin
result = super
if scope == :instance
result.reduce_class_type
else
result
end
end
end
|
#generic_defaults ⇒ Hash{String => ComplexType}
21
22
23
|
# File 'lib/solargraph/pin/closure.rb', line 21
def generic_defaults
@generic_defaults ||= {}
end
|
#generics ⇒ ::Array<String>
53
54
55
|
# File 'lib/solargraph/pin/closure.rb', line 53
def generics
@generics ||= docstring.tags(:generic).map(&:name)
end
|
#rbs_generics ⇒ String
62
63
64
65
66
|
# File 'lib/solargraph/pin/closure.rb', line 62
def rbs_generics
return '' if generics.empty?
"[#{generics.map(&:to_s).join(', ')}] "
end
|
#rebind(api_map) ⇒ void
This method returns an undefined value.
50
|
# File 'lib/solargraph/pin/closure.rb', line 50
def rebind api_map; end
|
#to_rbs ⇒ Object
57
58
59
|
# File 'lib/solargraph/pin/closure.rb', line 57
def to_rbs
rbs_generics + return_type.to_rbs
end
|