is_utf8?

is_utf8?() Instance Public methods

last

last(limit = 1) Instance Public methods Returns the last character of the string. If a limit is supplied, returns a substring from the end of the string until it reaches the limit value (counting backwards). If the given limit is greater than or equal to the string length, returns self. str = "hello" str.last # => "o" str.last(1) # => "o" str.last(2) # => "lo" str.last(0) # => "" str.last(6) # => "hello"

mb_chars

mb_chars() Instance Public methods Multibyte proxy mb_chars is a multibyte safe proxy for string methods. It creates and returns an instance of the ActiveSupport::Multibyte::Chars class which encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsulated string. name = 'Claus Müller' name.reverse # => "rell??M sualC" name.length # =>

parameterize

parameterize(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) %> # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>

pluralize

pluralize(count = nil, locale = :en) Instance Public methods Returns the plural form of the word in the string. If the optional parameter count is specified, the singular form will be returned if count == 1. For any other value of count the plural will be returned. If the optional parameter locale is specified, the word will be pluralized as a word of that language. By default, this parameter is set to :en. You must define your own inflection rules for languages other than English.

remove

remove(pattern) Instance Public methods Returns a new string with all occurrences of the pattern removed. Short-hand for String#gsub(pattern, '').

remove!

remove!(pattern) Instance Public methods Alters the string by removing all occurrences of the pattern. Short-hand for String#gsub!(pattern, '').

safe_constantize

safe_constantize() Instance Public methods safe_constantize tries to find a declared constant with the name specified in the string. It returns nil when the name is not in CamelCase or is not initialized. See ActiveSupport::Inflector#safe_constantize 'Module'.safe_constantize # => Module 'Class'.safe_constantize # => Class 'blargle'.safe_constantize # => nil

singularize

singularize(locale = :en) Instance Public methods The reverse of pluralize, returns the singular form of a word in a string. If the optional parameter locale is specified, the word will be singularized as a word of that language. By default, this parameter is set to :en. You must define your own inflection rules for languages other than English. 'posts'.singularize # => "post" 'octopi'.singularize # => "octopus" 'sheep'.singularize # => "she

squish

squish() Instance Public methods Returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each. Note that it handles both ASCII and Unicode whitespace. %{ Multi-line string }.squish # => "Multi-line string" " foo bar \n \t boo".squish # => "foo bar boo"