1- In nlab (here http://ncatlab.org/nlab/show/rank), for quite general modules, the rank is defined locally at $p\in Spec(R)$ as the dimension over the residue field $\kappa(p)$ of the $\kappa(p)$ vector space $M_p/pM_p$. When $M$ is of finite type, this is the local minimum of generators of $M_p$ over $R_p$
2- The usual definition of the rank of a module when this module is projective of finite type is locally the rank of the free module $M_p$ over $R_p$ (see here Rank of a module for instance). This function rank is locally constant, and therefore when $R$ is a domain, is the dimension of the vector space $M\otimes K$ over $K=R_0$.
3- When $R$ is a domain, Matsumura defines the rank of a quite general module $M$ by the maximum number of independent elements, that is the dimension of the vector space $M\otimes K$ over $K=R_0$.
Here in nLab, for quite general modules, the rank is defined locally at $p\in \mathrm{Spec}(R)$ as the dimension over the residue field $\kappa(p)$ of the $\kappa(p)$ vector space $M_p/pM_p$. When $M$ is of finite type, this is the local minimum of generators of $M_p$ over $R_p$.
The usual definition of the rank of a module when this module is projective of finite type is locally the rank of the free module $M_p$ over $R_p$. (see mathoverflow.net/questions/29993 for instance). This function rank is locally constant, and therefore when $R$ is a domain, is the dimension of the vector space $M\otimes K$ over $K=R_0$.
When $R$ is a domain, Matsumura defines the rank of a quite general module $M$ by the maximum number of independent elements, that is the dimension of the vector space $M\otimes K$ over $K=R_0$.
EDITEDIT: In case the ring $R$ is noetherian and $M$ is of finite type, we have the following generalization of Matsumura's definition, if $Q$ is the total ring of fraction of $R$, with the equivalence of all the following propositions
1- $M$ is of rank $r$
2- $M\otimes Q$ is a free rank $r$ module over $Q$
3- The maximum number of independent elements of $M$ is $r$
4- There exists a submodule $N$ of $M$ such that $M/N$ is torsionstatements:
5- For all prime $p$ associated to $R$, $M_p$ is free of rank $r$ over $R_p$
$M$ is of rank $r$.
$M\otimes Q$ is a free rank $r$ module over $Q$.
The maximum number of independent elements of $M$ is $r$.
There exists a submodule $N$ of $M$ such that $M/N$ is torsion.
For all prime $p$ associated to $R$, $M_p$ is free of rank $r$ over $R_p$.