This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Rails: String#classify
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
Create a class name from a table name like Rails does for table names to models. Note that this returns a string and not a Class. (To convert to an actual class follow classify with constantize.)
Examples
"egg_and_hams".classify #=> "EggAndHam"
"post".classify #=> "Post"
Usage The classify method is helpful when metaprogramming. I generally replace "strings".singularize.camelize with "strings".classify (and the classify implementation calls singularize and camelize for me).