Sha256: 158e0c47a602a95ee37aadfb7b2e30c2fe0df0abf14abeb34abac006286dcbde

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Steep
  InstanceMethodName = _ = Struct.new(:type_name, :method_name, keyword_init: true) do
    # @implements InstanceMethodName
    def to_s
      "#{type_name}##{method_name}"
    end

    def relative
      InstanceMethodName.new(type_name: type_name.relative!, method_name: method_name)
    end
  end

  SingletonMethodName = _ = Struct.new(:type_name, :method_name, keyword_init: true) do
    # @implements SingletonMethodName
    def to_s
      "#{type_name}.#{method_name}"
    end

    def relative
      SingletonMethodName.new(type_name: type_name.relative!, method_name: method_name)
    end
  end

  class ::Object
    def MethodName(string)
      case string
      when /#/
        type_name, method_name = string.split(/#/, 2)
        type_name or raise
        method_name or raise
        InstanceMethodName.new(type_name: RBS::TypeName.parse(type_name), method_name: method_name.to_sym)
      when /\./
        type_name, method_name = string.split(/\./, 2)
        type_name or raise
        method_name or raise
        SingletonMethodName.new(type_name: RBS::TypeName.parse(type_name), method_name: method_name.to_sym)
      else
        raise "Unexpected method name: #{string}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
steep-1.9.3 lib/steep/method_name.rb