Class: String
Instance Method Summary collapse
-
#camelize ⇒ Object
Converts a string camel case.
-
#underscore ⇒ Object
Converts a string to underscore form.
Instance Method Details
#camelize ⇒ Object
Converts a string camel case. Taken from Rails source.
3 4 5 |
# File 'lib/extensions/string.rb', line 3 def camelize self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end |
#underscore ⇒ Object
Converts a string to underscore form. Taken from Rails source.
8 9 10 |
# File 'lib/extensions/string.rb', line 8 def underscore self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase end |