# Core Extensions: String Access
Returns a substring of a string object. Same interface as
Returns a substring from the given position to the end of the string.
Returns a substring from the beginning of the string to the given position.
If the position is negative, it is counted from the end of the string.
to can be used in tandem.
Returns the first character, or a given number of characters up to the length of the string.
Returns the last character, or a given number of characters from the end of the string counting backwards.
# Core Extensions: String to Date/Time Conversion
Converts a string to a Time value. The
form parameter can be either
:local, defaults to
Converts a string to a Date value.
Converts a string to a DateTime value.
# Core Extensions: String Exclusion
The inverse of
# Core Extensions: String Filters
Returns a version of the given string without leading or trailing whitespace, and combines all consecutive whitespace in the interior to single spaces. Destructive version
squish! operates directly on the string instance.
Handles both ASCII and Unicode whitespace.
This command does such and such. Supported options are: -h This message ...
# Core Extensions: String Inflection
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.
Returns the singular form of the string. Accepts an optional
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.
constantize but returns
nil instead of raising
Converts strings to UpperCamelCase by default, if
:lower is given as param converts to lowerCamelCase instead.
Note: will also convert
:: which is useful for converting paths to namespaces.
Capitalizes all the words and replaces some characters in the string to create a nicer looking title.
Makes an underscored, lowercase form from the expression in the string. The reverse of
underscore will also change
/ to convert namespaces to paths.
Replaces underscores with dashes in the string.
Removes the module part from the constant expression in the string.
Removes the rightmost segment from the constant expression in the string.
Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
Preserve the case of the characters in a string with the
A very common use-case for
parameterize is to override the
to_param method of an ActiveRecord model to support more descriptive url slugs.
Creates the name of a table like Rails does for models to table names. Pluralizes the last word in the string.
Returns a class name string from a plural table name like Rails does for table names to models.
Capitalizes the first word, turns underscores into spaces, and strips a trailing
_id if present.
Converts just the first character to uppercase.
Creates a foreign key name from a class name. Pass
false param to disable adding
_ between name and
ActiveSupport is a utility gem of general-purpose tools used by the rest of the Rails framework.
One of the primary ways it provides these tools is by monkeypatching Ruby's native types. These are referred to as Core Extensions.