camelize

camelize(term, uppercase_first_letter = true) Instance Public methods 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. 'active_model'.camelize # => "ActiveModel" 'active_model'.camelize(:lower) # => "activeModel" 'active_model/errors'.camelize # => "ActiveModel::E

classify

classify(table_name) Instance Public methods Create a class name from a plural 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). 'egg_and_hams'.classify # => "EggAndHam" 'posts'.classify # => "Post" Singular names are not handled correctly: 'calculus'.classify # => "Calculu"

constantize

constantize(camel_cased_word) Instance Public methods Tries to find a constant with the name specified in the argument string. 'Module'.constantize # => Module 'Test::Unit'.constantize # => Test::Unit The name is assumed to be the one of a top-level constant, no matter whether it starts with â::â or not. No lexical context is taken into account: C = 'outside' module M C = 'inside' C # => 'inside' 'C'.constantize # => 'outside', same as ::C end

dasherize

dasherize(underscored_word) Instance Public methods Replaces underscores with dashes in the string. 'puni_puni'.dasherize # => "puni-puni"

deconstantize

deconstantize(path) Instance Public methods Removes the rightmost segment from the constant expression in the string. 'Net::HTTP'.deconstantize # => "Net" '::Net::HTTP'.deconstantize # => "::Net" 'String'.deconstantize # => "" '::String'.deconstantize # => "" ''.deconstantize # => "" See also demodulize.

demodulize

demodulize(path) Instance Public methods Removes the module part from the expression in the string. 'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections" 'Inflections'.demodulize # => "Inflections" See also deconstantize.

foreign_key

foreign_key(class_name, separate_class_name_and_id_with_underscore = true) Instance Public methods Creates a foreign key name from a class name. separate_class_name_and_id_with_underscore sets whether the method should put '_' between the name and 'id'. 'Message'.foreign_key # => "message_id" 'Message'.foreign_key(false) # => "messageid" 'Admin::Post'.foreign_key # => "post_id"

humanize

humanize(lower_case_and_underscored_word, options = {}) Instance Public methods Capitalizes the first word, turns underscores into spaces, and strips a trailing '_id' if present. Like titleize, this is meant for creating pretty output. The capitalization of the first word can be turned off by setting the optional parameter capitalize to false. By default, this parameter is true. humanize('employee_salary') # => "Employee salary" humanize('author_id')

inflections

inflections(locale = :en) Instance Public methods Yields a singleton instance of Inflector::Inflections so you can specify additional inflector rules. If passed an optional locale, rules for other languages can be specified. If not specified, defaults to :en. Only rules for English are provided. ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.uncountable 'rails' end

ordinal

ordinal(number) Instance Public methods Returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th. ordinal(1) # => "st" ordinal(2) # => "nd" ordinal(1002) # => "nd" ordinal(1003) # => "rd" ordinal(-11) # => "th" ordinal(-1021) # => "st"