Module: Moon::Utility::String

Defined in:
lib/moon/utility/string.rb

Class Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word) ⇒ Object



4
5
6
# File 'lib/moon/utility/string.rb', line 4

def self.camelize(lower_case_and_underscored_word)
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1}".upcase }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

.underscore(camel_cased_word) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/moon/utility/string.rb', line 8

def self.underscore(camel_cased_word)
  camel_cased_word.to_s.
    gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    tr("-", "_").
    downcase
end