Sha256: d70cf855c4d6d71ef33374d74e1325e38720986e9e2cfc15c6617d20661af739

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module Furnace
  class Type::Top
    class << self
      def normalize(*params)
        params
      end

      def new(*params)
        @instances[normalize(*params)]
      end

      protected

      def setup_singleton
        @instances = Hash.new do |hash, params|
          inst = allocate
          inst.send :initialize, *params
          inst.freeze

          hash[params] = inst
        end
      end

      def inherited(klass)
        klass.setup_singleton
      end
    end

    setup_singleton

    def to_type
      self
    end

    def subtype_of?(other)
      other.instance_of?(Type::Top) ||
          self == other
    end

    def supertype_of?(other)
      other.subtype_of?(self)
    end

    def variable?
      false
    end

    def replace_type_with(type, replacement)
      if self == type
        replacement.to_type
      else
        self
      end
    end

    def specialize(other)
      if self == other
        {}
      else
        raise ArgumentError, "cannot specialize #{self.to_s} with #{other.to_s}"
      end
    end

    def to_s
      'top'
    end

    def awesome_print(p=AwesomePrinter.new)
      p.type(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
furnace-0.4.0.beta.2 lib/furnace/type/top.rb