# File lib/facets/more/multiton.rb, line 102
  def self.append_features( klass )
    class << klass
      unless method_defined?(MULTITON_NEW_HOOK)
        alias_method MULTITON_NEW_HOOK, :new
      end

      def instance(*args, &block)
        k = begin
          # if the class defined 'multiton_id' we use this as the key
          send MULTITON_ID_HOOK, *args, &block
        rescue NameError
          # otherwise we simply use the argument list
          args
        end

        k = begin
          Marshal.dump(k)
        rescue TypeError
          k
        end

        unless obj = (POOLS[self] ||= {})[k]
          begin
            critical = Thread.critical
            Thread.critical = true
            obj = (POOLS[self][k] = send(MULTITON_NEW_HOOK, *args, &block))
          ensure
            Thread.critical = critical # restore state
          end
        end

        return obj
      end

      alias_method :create, :new
      alias_method :new, :instance
    end
  end