Returns of plural form of the string. Optionally takes a count parameter and returns singular form if count == 1. Also accepts a locale parameter for language-specific pluralization.
'post'.pluralize # => "posts"'octopus'.pluralize # => "octopi"'sheep'.pluralize # => "sheep"'words'.pluralize # => "words"'the blue mailman'.pluralize # => "the blue mailmen"'CamelOctopus'.pluralize # => "CamelOctopi"'apple'.pluralize(1) # => "apple"'apple'.pluralize(2) # => "apples"'ley'.pluralize(:es) # => "leyes"'ley'.pluralize(1, :es) # => "ley"
Returns the singular form of the string. Accepts an optional locale parameter.
'posts'.singularize # => "post"'octopi'.singularize # => "octopus"'sheep'.singularize # => "sheep"'word'.singularize # => "word"'the blue mailmen'.singularize # => "the blue mailman"'CamelOctopi'.singularize # => "CamelOctopus"'leyes'.singularize(:es) # => "ley"
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'blargle'.constantize # => NameError: wrong constant name blargle
Performs a constantize but returns nil instead of raising NameError.
'Module'.safe_constantize # => Module'Class'.safe_constantize # => Class'blargle'.safe_constantize # => nil
Converts strings to UpperCamelCase by default, if :lower is given as param converts to lowerCamelCase instead.
alias: camelcase
Note: will also convert / to :: which is useful for converting paths to namespaces.
'active_record'.camelize # => "ActiveRecord"'active_record'.camelize(:lower) # => "activeRecord"'active_record/errors'.camelize # => "ActiveRecord::Errors"'active_record/errors'.camelize(:lower) # => "activeRecord::Errors"
Capitalizes all the words and replaces some characters in the string to create a nicer looking title.
alias: titlecase