Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_extension/string.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#camelize ⇒ Object
This method converts an underscore_string into a CamelCaseString.
- #camelize_name ⇒ Object
- #camelize_path ⇒ Object
-
#underscore ⇒ Object
This method converts a CamelCaseString into an underscore_string.
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
#camelize ⇒ Object
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_name ⇒ Object
18 19 20 |
# File 'lib/core_extension/string.rb', line 18 def camelize_name self.gsub(/(?:^|_)(.)/) { $1.upcase } end |
#camelize_path ⇒ Object
14 15 16 |
# File 'lib/core_extension/string.rb', line 14 def camelize_path self.gsub(/\/(.?)/) { "::#{$1.upcase}" } end |
#underscore ⇒ Object
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 |