Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/tb-cli/camel_case.rb
Overview
See the 'tb-cli/cli/rack' module for initializing Rack-based projects to see where this modification is being used.
Instance Method Summary collapse
-
#underscore ⇒ Object
Stolen from StackOverflow: http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby.
Instance Method Details
#underscore ⇒ Object
Stolen from StackOverflow: http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
This converts a string from CamelCase to snake_case. This allows all String classes to call #underscore to get a proper conversion.
10 11 12 13 14 15 16 |
# File 'lib/tb-cli/camel_case.rb', line 10 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |