Recently I’ve been making my first custom library at work, and I’ve needed ways to turn strings into classes and classes into strings, I found some helpful methods for doing so by digging around a bit!
# This will return "Hello world"
"hello_world".humanize
# This will return Editor::Template
"Editor::Template".constantize
# This will return "hello_world"
"HelloWorld".underscore
# This will return "HelloWorld"
"hello_world".camelize
# This will return "hello-world"
"Hello World".parameterize
Published on Tuesday, 28 June 2011