From d6d21e6cfe0d6747d8d6c524ee8cb491b4cffa7e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 20 Sep 2013 13:40:25 +0200 Subject: [PATCH] Improved to_app_model. --- lib/core_ext/class.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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