Sha256: bad7f76b9d60aa5665f7851802effca64f3ac8c7f64e60fde72cf1ae865c2cef

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Yoda
  module Typing
    module Types
      class Method < Base
        # @return [Base]
        attr_reader :callee

        # @return [String]
        attr_reader :method_name

        # @param callee [Base]
        # @param method_name [String]
        # @param with_receiver [true, false]
        def initialize(callee, method_name, with_receiver: false)
          @callee = callee
          @method_name = method_name
        end

        def to_expression(resolver)
          callee_type = to_expression(callee)
          values = callee_type.instanciate(resolver.registry)
          Model::TypeExpressions::UnionType.new(
            values.map do |value|
              value.methods(visibility: visibility).select { |func| func.name == method_name }
            end.flatten
          )
        end

        def visilibity
          @self_call ? [:private, :public, :protected] : [:public]
        end

        def to_type_string
          "#{callee.to_type_string}##{method_name}"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/typing/types/method.rb
yoda-language-server-0.10.0 lib/yoda/typing/types/method.rb
yoda-language-server-0.9.0 lib/yoda/typing/types/method.rb
yoda-language-server-0.8.0 lib/yoda/typing/types/method.rb