Created
October 27, 2011 13:34
-
-
Save qoobaa/1319547 to your computer and use it in GitHub Desktop.
camelize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun activesupport-camelize (string &rest args) | |
| "camelizes string just like in ActiveSupport inflector" | |
| (and (= 0 (length args)) (setq args '(t))) | |
| (reduce (lambda (string replacement) | |
| (replace-regexp-in-string (car replacement) (cadr replacement) string)) | |
| '(("^." (lambda (match) (upcase match))) | |
| ("_." (lambda (match) (upcase (substring match 1)))) | |
| ("/.?" (lambda (match) (concat "::" (upcase (substring match 1)))) string)) | |
| :initial-value string | |
| :start (if (car args) 0 1))) | |
| (defun activesupport-camelize-word () | |
| "camelizes word just like in ActiveSupport inflector" | |
| (interactive) | |
| (insert-string | |
| (activesupport-camelize | |
| (delete-and-extract-region (point) (+ (point) (skip-chars-forward "_/:A-Za-z0-9")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment