Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_ext.rb
Instance Method Summary collapse
-
#camelize(first_letter_in_uppercase = true) ⇒ Object
opposites underscore defined above.
-
#underscore ⇒ Object
generates filenames from classnames the rails way.
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
opposites underscore defined above
8 9 10 11 12 13 14 |
# File 'lib/string_ext.rb', line 8 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else self.first + camelize(lower_case_and_underscored_word)[1..-1] end end |
#underscore ⇒ Object
generates filenames from classnames the rails way
3 4 5 |
# File 'lib/string_ext.rb', line 3 def underscore self.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase end |