What is the idea behind sheaves of rings on distinguished open sets In the book on algebraic geometry of Mumford (which can be found here), he said :

We want to enlarge the ring $R$ into a whole sheaves of rings on $SpecR$, written $\mathcal{O}_{SpecR}=\mathcal{O}_{X}$.

So he need to define $\mathcal{O}_{X}(U)$ for $U$ is an open set in $X$, in particular he need to define $\mathcal{O}_{X}(X_f)$ for some distinguished open subset $X_f$. And he said 

We want to define : $\mathcal{O}_{X}(X_f)=R_f$=localization of the ring $R$ w.r.t multiplicative system $\lbrace 1,f,f^2,..\rbrace$

My question is : Why do we want to define the sheaf $\mathcal{O}_{X}(X_f)$ to be $R_f$ ?
Back to case of affine variety $V$, $V\setminus V(f)$ is a quasi-affine variety with the ring of regular function $k[V]_f$. So can we think about the sections of $\mathcal{O}_{X}(X_f)$ as the regular function on some spaces ?
 A: You can think of $X_f$ as the the set of those points where $f$ does not vanish (this is true verbatim in the case of classical varieties, but also for schemes when you use the structure sheaf and think of $f$ as a function valued in the residue fields). Thus $f$ should be invertible on $X_f$, and therefore $r/f^k$ should be a regular function on $X_f$, for every regular function $r$ on $X$. There is no reason to impose more regular functions. So we just define $\mathcal{O}(X_f) := R_f$.
In the end, it is just a definition, and when you work with it you will see that it is the right one. You have already mentioned that this fits perfectly to the case of classical varieties.
A: To add just a little bit to Martin's already excellent answer. 
Philosophically, we like the following idea: given a space $X$, we can learn a lot from $X$ by a ring of functions on this space. However, the whole ring loses a ton of information. So instead, lets remember what happens locally: so we get a sheaf of functions on a space.
Now given a ring $R$, we do the math-y thing and reverse the above construction. We want a space $X$ on which $R$ is the ring of functions. We want it to be as natural a construction as possible. Grothendieck's insight was that the "set of prime ideals" forms a good "set of points of a space" to do geometry. Again though, if we only remember the global information, we lose a huge amount of information that is intrinsically. 
So working with $Spec(R)$ and the ring of functions $R$ gives you natural motivation to not only study a ring, but all its quotients (functions on closed sets) and all its localizations (functions on open sets) at once.
Why localization? It really comes down to what localization does to the behaviour under localization of the lattice of prime ideals. Think first about the process of passing from $R$ to $R/I$ for some ideal $I$. What are the prime ideals in $R/I$ - they are those prime ideals of $R$ containing $I$. Containing a prime ideal is what we take to be "vanish at that point". This is the key idea: the property of containing a prime ideal is the right replacement for vanishing in the classical setting. 
It is a good idea to take a good look at the Nullstellensatz, and extract the above statement in the classical setting. 
Now why localization? In a similar manner to the above discussion, the prime ideals that survive localization are the ones that dont intersect the set that you are inverting. If you want to think about a single function $f$, then localizing at $f$ to get $R_f$ this tells us that the prime ideals of the localization are (more precisely, correspond to) those in $R$ which do not contain $f$: i.e. the set of points where $f$ doesnt vanish. 
One should write down and chase the appropriate diagrams to make sure that the "correspondence between prime ideals" for the two cases I mentioned above are functorial, that they behave well with morphisms, but thats the intuition.
