class ServerList < Array
  def at(index)
    if index.is_a? String
      select do |server|
        server.endpoint == index
      end
    else
      super
    end
  end

  def <<(server)
    if at(server.endpoint).size == 0
      super
    else
      puts self.map(&:endpoint).inspect
      raise ArgumentError, "Server at mount point #{server.endpoint} is already present."
    end
  end
  alias push <<

  alias clear! clear
end


class ServerList < Array
  def at(index)
    if index.is_a? String
      select do |server|
        server.endpoint == index
      end
    else
      super
    end
  end

  def <<(server)
    if at(server.endpoint).size == 0
      super
    else
      puts self.map(&:endpoint).inspect
      raise ArgumentError, "Server at mount point #{server.endpoint} is already present."
    end
  end
  alias push <<

  def clear!
    self.each do |server|
      server.stop
    end
    clear
  end
end


Make sure that if there is a listening server that it's shut down before clearing the server list.
Make sure that if there is a listening server that it's shut down before clearing the server list.
