diff --git a/lib/core_ext/class.rb b/lib/core_ext/class.rb index b1dac68b7..b1c3c4695 100644 --- a/lib/core_ext/class.rb +++ b/lib/core_ext/class.rb @@ -1,6 +1,10 @@ class Class def to_app_model - name = self.to_s.downcase - name.gsub( /::/, '_' ) + camel_cased_word = self.to_s + camel_cased_word.gsub(/::/, '_'). + gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). + gsub(/([a-z\d])([A-Z])/,'\1_\2'). + tr("-", "_"). + downcase end end