Class: String

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

Instance Method Summary collapse

Instance Method Details

#camelizeObject

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

#underscoreObject

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