instance method
acronym
Ruby on Rails 3.2.22.5
Since v3.2.22.5Signature
acronym(word)
Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore string that contains the acronym will retain the acronym when passed to camelize, humanize, or titleize. A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will convert the acronym into a non-delimited single lowercase word when passed to underscore.
Examples:
acronym 'HTML'
titleize 'html' #=> 'HTML'
camelize 'html' #=> 'HTML'
underscore 'MyHTML' #=> 'my_html'
The acronym, however, must occur as a delimited unit and not be part of another word for conversions to recognize it:
acronym 'HTTP'
camelize 'my_http_delimited' #=> 'MyHTTPDelimited'
camelize 'https' #=> 'Https', not 'HTTPs'
underscore 'HTTPS' #=> 'http_s', not 'https'
acronym 'HTTPS'
camelize 'https' #=> 'HTTPS'
underscore 'HTTPS' #=> 'https'
Note: Acronyms that are passed to pluralize will no longer be recognized, since the acronym will not occur as a delimited unit in the pluralized result. To work around this, you must specify the pluralized form as an acronym as well:
acronym 'API'
camelize(pluralize('api')) #=> 'Apis'
acronym 'APIs'
camelize(pluralize('api')) #=> 'APIs'
acronym may be used to specify any word that contains an acronym or otherwise needs to maintain a non-standard capitalization. The only restriction is that the word must begin with a capital letter.
Examples:
acronym 'RESTful'
underscore 'RESTful' #=> 'restful'
underscore 'RESTfulController' #=> 'restful_controller'
titleize 'RESTfulController' #=> 'RESTful Controller'
camelize 'restful' #=> 'RESTful'
camelize 'restful_controller' #=> 'RESTfulController'
acronym 'McDonald'
underscore 'McDonald' #=> 'mcdonald'
camelize 'mcdonald' #=> 'McDonald'
Parameters
-
wordreq
Source
# File activesupport/lib/active_support/inflector/inflections.rb, line 77
def acronym(word)
@acronyms[word.downcase] = word
@acronym_regex = /#{@acronyms.values.join("|")}/
end
Defined in activesupport/lib/active_support/inflector/inflections.rb line 77
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector::Inflections