Move ruby steps to the end of the Dockerfile

This will let Docker reuse more of the layers across the different images for different ruby versions.