Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_extension/string.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.underscore(word) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/core_extension/string.rb', line 22

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

Instance Method Details

#camelizeObject

This method converts an underscore_string into a CamelCaseString.



10
11
12
# File 'lib/core_extension/string.rb', line 10

def camelize
  self.camelize_path.camelize_name
end

#camelize_nameObject



18
19
20
# File 'lib/core_extension/string.rb', line 18

def camelize_name
  self.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#camelize_pathObject



14
15
16
# File 'lib/core_extension/string.rb', line 14

def camelize_path
  self.gsub(/\/(.?)/) { "::#{$1.upcase}" }
end

#underscoreObject

This method converts a CamelCaseString into an underscore_string.



5
6
7
# File 'lib/core_extension/string.rb', line 5

def underscore
  self.class.underscore self.to_s.dup
end