Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyify_keys.rb

Instance Method Summary collapse

Instance Method Details

#to_underscore!Object

converts a camel_cased string to a underscore string, Same way ActiveSupport does string.underscore



21
22
23
24
25
26
27
# File 'lib/rubyify_keys.rb', line 21

def to_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