acronym

acronym(word)
Instance Public methods

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.

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.

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'
doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.