Module: Predicated::StringUtils

Defined in:
lib/predicated/string_utils.rb

Class Method Summary collapse

Class Method Details

.underscore(camel_cased_word) ⇒ Object

Ripped from activesupport.

If I start using a bunch of code from that project I’ll create a dependency. I hope this is not bad form.



7
8
9
10
11
12
13
# File 'lib/predicated/string_utils.rb', line 7

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

.uppercamelize(lower_case_and_underscored_word) ⇒ Object



15
16
17
# File 'lib/predicated/string_utils.rb', line 15

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