Module: Metaforce::CoreExtensions::String

Defined in:
lib/metaforce/core_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#camelcaseObject



5
6
7
8
9
10
# File 'lib/metaforce/core_extensions/string.rb', line 5

def camelcase
  str = dup
  str.gsub!(/^[a-z]|_[a-z]/) { |a| a.upcase }
  str.gsub!('_', '')
  str
end

#lower_camelcaseObject



12
13
14
15
16
17
# File 'lib/metaforce/core_extensions/string.rb', line 12

def lower_camelcase
  str = dup
  str.gsub!(/_[a-z]/) { |a| a.upcase }
  str.gsub!('_', '')
  str
end

#underscoreObject



19
20
21
22
23
24
25
# File 'lib/metaforce/core_extensions/string.rb', line 19

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