DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile


  • submit to reddit
        Emacs lisp macro for rails development to reverse the order of the columns in rename_column
Could use this approach to automatically rewrite most of the migration's "down"

(defun rails-reverse-rename-column ()
  "In a rails migration, from point to end of buffer, reverse the order of renamed columns"
    (while (re-search-forward "rename_column *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *, *\"\\([^\"]*\\)\" *$" nil t)
       (replace-match "rename_column \"\\1\", \"\\3\", \"\\2\""))))