Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/jmx4r.rb
Instance Method Summary collapse
-
#camel_case ⇒ Object
Transform a snake_case String to a camelCase String with a lowercase initial.
-
#snake_case ⇒ Object
Transform a CamelCase String to a snake_case String.
Instance Method Details
#camel_case ⇒ Object
Transform a snake_case String to a camelCase String with a lowercase initial. – Code has been taken from ActiveSupport
19 20 21 22 |
# File 'lib/jmx4r.rb', line 19 def camel_case name = gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } name[0].chr.downcase + name[1..-1] end |
#snake_case ⇒ Object
Transform a CamelCase String to a snake_case String. – Code has been taken from ActiveRecord
8 9 10 11 12 13 14 |
# File 'lib/jmx4r.rb', line 8 def snake_case self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |