ordinalize

ordinalize(number) Instance Public methods Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th. ordinalize(1) # => "1st" ordinalize(2) # => "2nd" ordinalize(1002) # => "1002nd" ordinalize(1003) # => "1003rd" ordinalize(-11) # => "-11th" ordinalize(-1021) # => "-1021st"

parameterize

parameterize(string, sep = '-') Instance Public methods Replaces special characters in a string so that it may be used as part of a 'pretty' URL. class Person def to_param "#{id}-#{name.parameterize}" end end @person = Person.find(1) # => #<Person id: 1, name: "Donald E. Knuth"> <%= link_to(@person.name, person_path(@person)) %> # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>

pluralize

pluralize(word, locale = :en) Instance Public methods Returns the plural form of the word in the string. If passed an optional locale parameter, the word will be pluralized using rules defined for that language. By default, this parameter is set to :en. 'post'.pluralize # => "posts" 'octopus'.pluralize # => "octopi" 'sheep'.pluralize # => "sheep" 'words'.pluralize # => "words" 'CamelOctopus'.pluralize # => "CamelOctopi"

safe_constantize

safe_constantize(camel_cased_word) Instance Public methods Tries to find a constant with the name specified in the argument string. 'Module'.safe_constantize # => Module 'Test::Unit'.safe_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'.safe_constantize # => 'ou

singularize

singularize(word, locale = :en) Instance Public methods The reverse of pluralize, returns the singular form of a word in a string. If passed an optional locale parameter, the word will be singularized using rules defined for that language. By default, this parameter is set to :en. 'posts'.singularize # => "post" 'octopi'.singularize # => "octopus" 'sheep'.singularize # => "sheep" 'word'.singularize # => "word" 'CamelOctopi'.si

tableize

tableize(class_name) Instance Public methods Create the name of a table like Rails does for models to table names. This method uses the pluralize method on the last word in the string. 'RawScaledScorer'.tableize # => "raw_scaled_scorers" 'egg_and_ham'.tableize # => "egg_and_hams" 'fancyCategory'.tableize # => "fancy_categories"

titleize

titleize(word) Instance Public methods Capitalizes all the words and replaces some characters in the string to create a nicer looking title. titleize is meant for creating pretty output. It is not used in the Rails internals. titleize is also aliased as titlecase. 'man from the boondocks'.titleize # => "Man From The Boondocks" 'x-men: the last stand'.titleize # => "X Men: The Last Stand" 'TheManWithoutAPast'.titleize # => "The Man Without A Past" 'raiders_of_the

transliterate

transliterate(string, replacement = "?") Instance Public methods Replaces non-ASCII characters with an ASCII approximation, or if none exists, a replacement character which defaults to â?â. transliterate('Ãrøskøbing') # => "AEroskobing" Default approximations are provided for Western/Latin characters, e.g, âøâ, âñâ, âéâ, âÃâ, etc. This method is I18n aware, so you can set up custom approximations for a locale. This can be useful, for example, to transliterate German's âüâ

underscore

underscore(camel_cased_word) Instance Public methods Makes an underscored, lowercase form from the expression in the string. Changes '::' to '/' to convert namespaces to paths. 'ActiveModel'.underscore # => "active_model" 'ActiveModel::Errors'.underscore # => "active_model/errors" As a rule of thumb you can think of underscore as the inverse of camelize, though there are cases where that does not hold: 'SSLError'.underscore.camelize # => "SslError"

new

new(parent = nil) Class Public methods