The moment of inertia is defined as

$$I = \int r^2 dm$$

but I am not sure how to proceed with solving the above integral. All examples I have seen seem to be done with different strategies. They usually start: "well consider this part of the mass $dm$" and then suddenly just plug in $2 \pi r $ and the answer miraculously pops out.

I can not find some (good) guidelines on how to solve the integral. What function is actually integrated, because both mass $m$ and distance $r$ can be variable in one another:

$$I = \int f(m(r),r(m)) r^2 dr$$