Sha256: 64a6cceb9cadea365ef32e0c9ff55c25582d9768d0f8473cce370fd7dd2342bb

Contents?: true

Size: 1.19 KB

Versions: 35

Compression:

Stored size: 1.19 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: TypeName(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: TypeName(type_name), method_name: method_name.to_sym)
      else
        raise "Unexpected method name: #{string}"
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
steep-1.6.0.pre.2 lib/steep/method_name.rb
steep-1.6.0.pre.1 lib/steep/method_name.rb
steep-1.5.3 lib/steep/method_name.rb
steep-1.5.2 lib/steep/method_name.rb
steep-1.5.1 lib/steep/method_name.rb
steep-1.5.0 lib/steep/method_name.rb
steep-1.5.0.pre.6 lib/steep/method_name.rb
steep-1.5.0.pre.5 lib/steep/method_name.rb
steep-1.5.0.pre.4 lib/steep/method_name.rb
steep-1.5.0.pre.3 lib/steep/method_name.rb
steep-1.5.0.pre.2 lib/steep/method_name.rb
steep-1.5.0.pre.1 lib/steep/method_name.rb
steep-1.4.0 lib/steep/method_name.rb
steep-1.4.0.dev.5 lib/steep/method_name.rb
steep-1.4.0.dev.4 lib/steep/method_name.rb