Jay Fields
Posts: 765
Nickname: jayfields
Registered: Sep, 2006
Jay Fields is a software developer for ThoughtWorks
Rails: String#camelize
Posted: Nov 3, 2007 3:02 AM
This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Rails: String#camelize
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jay Fields
Latest Posts From Jay Fields Thoughts
Advertisement
Documentation By default, camelize converts strings to UpperCamelCase. If the argument to camelize is set to ":lower" then camelize produces lowerCamelCase. camelize will also convert ’/’ to ’::’ which is useful for converting paths to namespaces Examples"active_record".camelize #=> "ActiveRecord" "active_record".camelize(:lower) #=> "activeRecord" "active_record/errors".camelize #=> "ActiveRecord::Errors" "active_record/errors".camelize(:lower) #=> "activeRecord::Errors" Usage I generally use camelize when metaprogrammming to convert from a underscored version of a class name.Test require ' rubygems' require ' active_support' require ' test/unit' require ' dust' unit_tests do test " change underscored word to camelized word" do assert_equal " AClassName" , " a_class_name" . camelize end end
Read: Rails: String#camelize