Module: Treat::Helpers::String::CamelCaseable
- Defined in:
- lib/treat/helpers/string.rb
Overview
Transform an un_camel_cased string into a CamelCased string. This is available on String and Symbol.
Constant Summary collapse
- Regex =
Regex for camel casing.
/^[a-z]|_[a-z]/
- @@cc_cache =
A cache to optimize camel casing.
{}
Instance Method Summary collapse
-
#camel_case ⇒ Object
(also: #cc)
Convert un_camel_case to CamelCase.
Instance Method Details
#camel_case ⇒ Object Also known as: cc
Convert un_camel_case to CamelCase.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/treat/helpers/string.rb', line 52 def camel_case o_phrase, phrase = to_s, to_s.dup if @@cc_cache[o_phrase] return @@cc_cache[o_phrase] end if Treat.core.acronyms.include?(phrase.downcase) phrase = phrase.upcase else phrase.gsub!(Regex) { |a| a.upcase } phrase.gsub!('_', '') end @@cc_cache[o_phrase] = phrase end |