Let Xk be a sequence of independent and identically distributed random variables taking values in a compact metric space Ω, and consider the problem of estimating the law of X1 in a Bayesian framework. A conjugate family of priors for nonparametric Bayesian inference is the Dirichlet process priors popularized by Ferguson. We prove that if the prior distribution is Dirichlet, then the sequence of posterior distributions satisfies a large-deviation principle, and give an explicit expression for the rate function. As an application, we obtain an asymptotic formula for the predictive probability of ruin in the classical gambler's ruin problem.