Sha256: 25be93bd768237e3949a807a1c39edf17cb0bc9bc85057bdf593eb0ea9a2541d

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

Contents

module RBS
  class TypeName
    attr_reader :namespace
    attr_reader :name
    attr_reader :kind

    def initialize(namespace:, name:)
      @namespace = namespace
      @name = name
      @kind = case name.to_s[0,1]
              when /[A-Z]/
                :class
              when /[a-z]/
                :alias
              when "_"
                :interface
              end
    end

    def ==(other)
      other.is_a?(self.class) && other.namespace == namespace && other.name == name
    end

    alias eql? ==

    def hash
      self.class.hash ^ namespace.hash ^ name.hash
    end

    def to_s
      "#{namespace.to_s}#{name}"
    end

    def to_json(*a)
      to_s.to_json(*a)
    end

    def to_namespace
      namespace.append(self.name)
    end

    def class?
      kind == :class
    end

    def alias?
      kind == :alias
    end

    def absolute!
      self.class.new(namespace: namespace.absolute!, name: name)
    end

    def absolute?
      namespace.absolute?
    end

    def relative!
      self.class.new(namespace: namespace.relative!, name: name)
    end

    def interface?
      kind == :interface
    end

    def with_prefix(namespace)
      self.class.new(namespace: namespace + self.namespace, name: name)
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
rbs-0.11.0 lib/rbs/type_name.rb
rbs-0.10.0 lib/rbs/type_name.rb
rbs-0.9.1 lib/rbs/type_name.rb
rbs-0.9.0 lib/rbs/type_name.rb
rbs-0.8.0 lib/rbs/type_name.rb
rbs-0.7.0 lib/rbs/type_name.rb
rbs-0.6.0 lib/rbs/type_name.rb
rbs-0.5.0 lib/rbs/type_name.rb
rbs-0.4.0 lib/rbs/type_name.rb
rbs-0.3.1 lib/rbs/type_name.rb
rbs-0.3.0 lib/rbs/type_name.rb
rbs-0.2.0 lib/rbs/type_name.rb
steep-0.16.0 vendor/ruby-signature/lib/rbs/type_name.rb
steep-0.15.0 vendor/ruby-signature/lib/rbs/type_name.rb