Handy Rails string functions
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!
Humanize
# This will return "Hello world"
"hello_world".humanize
Constantize
# This will return Editor::Template
"Editor::Template".constantize
Underscore
# This will return "hello_world"
"HelloWorld".underscore
Camelize
# This will return "HelloWorld"
"hello_world".camelize
Parameterize
# This will return "hello-world"
"Hello World".parameterize
Published on Tuesday, 28 June 2011
All posts
- How to reach your host machine from VirtualBox
- Running RSpec with optional SimpleCov
- Handy Rails string functions
- Sexy documenting with Docco & Rocco
- Playing with CoffeeScript
- Time to learn: Behaviour Driven Development
- Getting up and running with Cucumber and Test::Unit
- My HTML Toolkits
- First networking meeting
- Using php.activerecord with Zend Framework
- How to create a Zend Controller Plugin
- JavaScript CDATA