strip_heredoc

strip_heredoc() Instance Public methods Strips indentation in heredocs. For example in if options[:usage] puts <<-USAGE.strip_heredoc This command does such and such. Supported options are: -h This message ... USAGE end the user would see the usage message aligned against the left margin. Technically, it looks for the least indented line in the whole string, and removes that amount of leading whitespace.

squish!

squish!() Instance Public methods Performs a destructive squish. See #squish.

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"

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

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

remove!

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

remove

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

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.

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>

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 # =>