Sha256: f96cbe6d5fd2f11abb84db4618b0fa8a5e7b8a604c81faa10edb5fea31fc84b1

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

module Steep
  module TypeName
    class Base
      attr_reader :name

      def initialize(name:)
        @name = name
      end

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

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

      alias eql? ==

      def to_s
        name.to_s
      end

      def map_module_name
        self.class.new(name: yield(name))
      end
    end

    class Interface < Base
      def map_module_name
        self
      end
    end

    class Class < Base
      attr_reader :constructor

      def to_s
        k = case constructor
            when nil
              ""
            when true
              " constructor"
            when false
              " noconstructor"
            end

        "#{name}.class#{k}"
      end

      def initialize(name:, constructor:)
        super(name: name)
        @constructor = constructor
      end

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

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

      NOTHING = Object.new

      def updated(constructor: NOTHING)
        if NOTHING == constructor
          constructor = self.constructor
        end

        self.class.new(name: name, constructor: constructor)
      end

      def map_module_name
        self.class.new(name: yield(name), constructor: constructor)
      end
    end

    class Module < Base
      def to_s
        "#{name}.module"
      end
    end

    class Instance < Base; end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
steep-0.4.0 lib/steep/type_name.rb
steep-0.3.0 lib/steep/type_name.rb
steep-0.2.0 lib/steep/type_name.rb
steep-0.1.0 lib/steep/type_name.rb