class Solargraph::Pin::Block

Attributes

receiver[R]

The signature of the method that receives this block.

@return [Parser::AST::Node]

Public Class Methods

new(receiver: nil, args: [], **splat) click to toggle source
Calls superclass method
# File lib/solargraph/pin/block.rb, line 11
def initialize receiver: nil, args: [], **splat
  super(**splat)
  @receiver = receiver
  @parameters = args
end

Public Instance Methods

binder() click to toggle source
# File lib/solargraph/pin/block.rb, line 23
def binder
  @binder || closure.binder
end
parameter_names() click to toggle source

@return [Array<String>]

# File lib/solargraph/pin/block.rb, line 33
def parameter_names
  @parameter_names ||= parameters.map(&:name)
end
parameters() click to toggle source

@return [Array<String>]

# File lib/solargraph/pin/block.rb, line 28
def parameters
  @parameters ||= []
end
rebind(api_map) click to toggle source

@param api_map [ApiMap] @return [void]

# File lib/solargraph/pin/block.rb, line 19
def rebind api_map
  @binder ||= binder_or_nil(api_map)
end

Private Instance Methods

binder_or_nil(api_map) click to toggle source

@param api_map [ApiMap] @return [ComplexType, nil]

# File lib/solargraph/pin/block.rb, line 41
def binder_or_nil api_map
  return nil unless receiver
  word = receiver.children.find { |c| c.is_a?(::Symbol) }.to_s
  return nil unless api_map.rebindable_method_names.include?(word)
  chain = Parser.chain(receiver, location.filename)
  locals = api_map.source_map(location.filename).locals_at(location)
  if ['instance_eval', 'instance_exec', 'class_eval', 'class_exec', 'module_eval', 'module_exec'].include?(chain.links.last.word)
    return chain.base.infer(api_map, self, locals)
  else
    receiver_pin = chain.define(api_map, self, locals).first
    if receiver_pin && receiver_pin.docstring
      ys = receiver_pin.docstring.tag(:yieldself)
      if ys && ys.types && !ys.types.empty?
        return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace)
      end
    end
  end
  nil
end