A function f:R\to R, where R is a commutative ring with unit element, is called \emph{polyfunction} if it admits a polynomial representative p\in R[x]. Based on this notion we introduce ring invariants which associate to R the numbers s(R) and s(R';R), where R' is the subring generated by 1. For the ring R=\mathbb Z/n\mathbb Z the invariant s(R) coincides with the number theoretic \emph{Smarandache function} s(n). If every function in a ring R is a polyfunction, then R is a finite field according to the Rédei-Szele theorem, and it holds that s(R)=|R|. However, the condition s(R)=|R| does not imply that every function f:R\to R is a polyfunction. We classify all finite commutative rings R with unit element which satisfy s(R)=|R|. For infinite rings R, we obtain a bound on the cardinality of the subring R' and for s(R';R) in terms of s(R). In particular we show that |R'|\leqslant s(R)!. We also give two new proofs for the Rédei-Szele theorem which are based on our results.