I'm a bit confused about a proof of the following proposition in Chapter II.2 of Hartshorne's Algebraic Geometry.
Prop. 2.2.a: Let $A$ be a ring and $(Spec(A), \mathcal{O})$ its spectrum. For any $\mathfrak{p} \in Spec(A)$, the stalk $\mathcal{O}_\mathfrak{p}$ is isomorphic to the local ring $A_\mathfrak{p}$.
I understand how he defines the homomorphism $\varphi: \mathcal{O}_\mathfrak{p} \rightarrow A_\mathfrak{p}$ by taking a representative $[(s, V)]$, $s \in \mathcal{O}(V)$, of the stalk $\mathcal{O}_\mathfrak{p}$ and sending it to $s(\mathfrak{p}) \in A_\mathfrak{p}$. I'm having trouble parsing his proof of surjectivity and how to think about the open sets $D(f)$. Hartshorne says that $\varphi$ is surjective since any $a/f$, $a,f \in A$, $f \notin \mathfrak{p}$, defines a section of $\mathcal{O}$ over $D(f)$, why is this so?
Does this mean that we're saying we can view $a/f$ as the element of $\mathcal{O}(D(f))$ which is identically $a/f$ as a function $D(f) \rightarrow \bigsqcup_{\mathfrak{q} \in D(f)}A_\mathfrak{q}$? Then we can view this as a representative $(a/f, D(f))$ in the stalk which maps to $a/f$ under $\varphi$?
This last question isn't really well formed, but more generally, since the $D(f)$ form a base for the topology of $Spec(A)$, should I just think about $\mathcal{O}$ at the level of the sections above the $D(f)$ which I can think about as elements of localizations of $A$? (This seems to be what part b of this proposition is saying, but I think my intuition from regular functions over varieties as locally quotients of polynomials is leading me astray).
Yes, you are viewing $a/f$ as a section over $D(f)$ which takes the value $a/f$ in different localized rings at all points of $D(f)$. For your last question, there is a notion of extending sheaf on a basis which allows one to view the structure sheaf as given by a compatible data of sections on the basis. More details about the latter can be found in Ravi Vakil's notes or Mumford's book.