Class: Solargraph::Pin::Closure
- Defined in:
- lib/solargraph/pin/closure.rb
Instance Attribute Summary collapse
-
#scope ⇒ ::Symbol
readonly
:class or :instance.
Attributes inherited from Base
#code_object, #location, #name, #path, #return_type, #source, #type_location
Attributes included from Common
Instance Method Summary collapse
- #binder ⇒ Object
- #context ⇒ Object
- #gates ⇒ ::Array<String>
- #generics ⇒ ::Array<String>
-
#initialize(scope: :class, generics: nil, **splat) ⇒ Closure
constructor
A new instance of Closure.
- #rbs_generics ⇒ String
- #to_rbs ⇒ String
Methods inherited from Base
#==, #all_rooted?, #best_location, #comments, #completion_item_kind, #deprecated?, #desc, #directives, #docstring, #erase_generics, #filename, #identity, #infer, #inspect, #macros, #maybe_directives?, #nearly?, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #realize, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_s, #transform_types, #try_merge!, #type_desc, #typify, #variable?
Methods included from Documenting
#documentation, normalize_indentation, strip_html_comments
Methods included from Conversions
#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#comments, #name, #namespace, #path, #return_type
Constructor Details
#initialize(scope: :class, generics: nil, **splat) ⇒ Closure
Returns a new instance of Closure.
11 12 13 14 15 |
# File 'lib/solargraph/pin/closure.rb', line 11 def initialize scope: :class, generics: nil, **splat super(**splat) @scope = scope @generics = generics end |
Instance Attribute Details
#scope ⇒ ::Symbol (readonly)
Returns :class or :instance.
7 8 9 |
# File 'lib/solargraph/pin/closure.rb', line 7 def scope @scope end |
Instance Method Details
#binder ⇒ Object
28 29 30 |
# File 'lib/solargraph/pin/closure.rb', line 28 def binder @binder || context end |
#context ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/solargraph/pin/closure.rb', line 17 def context @context ||= begin result = super if scope == :instance result.reduce_class_type else result end end end |
#gates ⇒ ::Array<String>
33 34 35 36 37 |
# File 'lib/solargraph/pin/closure.rb', line 33 def gates # @todo This check might not be necessary. There should always be a # root pin closure ? closure.gates : [''] end |
#generics ⇒ ::Array<String>
40 41 42 |
# File 'lib/solargraph/pin/closure.rb', line 40 def generics @generics ||= docstring.(:generic).map(&:name) end |
#rbs_generics ⇒ String
50 51 52 53 54 |
# File 'lib/solargraph/pin/closure.rb', line 50 def rbs_generics return '' if generics.empty? '[' + generics.map { |gen| gen.to_s }.join(', ') + '] ' end |
#to_rbs ⇒ String
45 46 47 |
# File 'lib/solargraph/pin/closure.rb', line 45 def to_rbs rbs_generics + return_type.to_rbs end |