Class: UnderscorizeKeys
- Inherits:
-
Object
- Object
- UnderscorizeKeys
- Defined in:
- lib/underscorize_keys.rb
Class Method Summary collapse
Class Method Details
.do(data) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/underscorize_keys.rb', line 2 def self.do data return unless data.is_a? Hash data.transform_keys! &:to_s data.transform_keys!{ |k| k.gsub(/(.)([A-Z])/,'\1_\2').downcase } data.each do |x,y| if y.is_a? Hash self.do(y) elsif y.is_a? Array y.each{|z| self.do(z) if z.is_a?(Hash)} end end end |