In Emacs I use the following function, found somewhere on the net.

(defun iwb ()
  "Indent whole buffer."
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

it relies on ruby-mode.el to indent Ruby sources.
Probably something similar can be written/found for vim.