Ramanujan's reasoning is analysed in detail by Berndt, in his discussion of chapters 6,7,8 of <A HREF="https://doi.org/10.1007/978-1-4612-1088-7_7">Ramanujan's notebooks</A>. Ramanujan starts from the <A HREF="https://en.wikipedia.org/wiki/Euler–Maclaurin_formula">Euler-MacLaurin summation formula</A>,
$$\sum_{k=1}^x f(k)=C +\int_1^x f(t)\,dt+\tfrac{1}{2}f(x)+\sum_{k\geq 1}\frac{B_{2k}}{(2k)!}\frac{d^{2k-1}}{dx^{2k-1}}f(x),$$
and focuses on the constant $C$, which he uses to find the asymptotic expansion of $\sum_{k=1}^x f(k)$ as $x\rightarrow\infty$. This approach was made somewhat more rigorous by Hardy.


In this way Ramanujan obtained the notorious identities $\sum 1 =-\tfrac{1}{2}$ and $\sum k = -\tfrac{1}{12}$. For a $p$-adic interpretation of the latter sum, see <A HREF="https://mathoverflow.net/q/84663/11260">this MO post.</A>