Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created October 27, 2011 13:34
Show Gist options
  • Save qoobaa/1319547 to your computer and use it in GitHub Desktop.
Save qoobaa/1319547 to your computer and use it in GitHub Desktop.
camelize
(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