Methods
1.camelcase
View
camelcase(first_letter = :upper)
Alias for camelize
2.camelize
View
camelize(first_letter = :upper)
camelize converts strings to UpperCamelCase.It can be set to lower to produce LowerCamelCase
>> 'active_record'.camelize
=> "ActiveRecord"
>> 'active_record'.camelize(:lower)
=> "activeRecord"
>> 'active_record/errors'.camelize(:lower)
=> "activeRecord::Errors"
>> 'active_record/errors'.camelize
=> "ActiveRecord::Errors"
3.classify
View
Creates a class name from a plural table name.This returns a string and not a class
>> 'article_and_authors'.classify
=> "ArticleAndAuthor"
>> 'articles'.classify
=> "Article"
4.constantize
View
constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.
>> 'Module'.constantize
=> Module
>> 'Class'.constantize
=> Class
5.dasherize
View
Replaces underscores with dashes in the string
>> 'juse_jude'.dasherize
=> "juse-jude"
6.humanize
View
Capitalizes the first word, turns underscores into spaces, and strips ‘_id’. Like titleize, this is meant for creating pretty output.
>> 'post_comment'.humanize
=> "Post comment"
>> 'post_id'.humanize
=> "Post"
No comments :
Post a Comment