class.rb 325 B

123456789101112131415
  1. class Class
  2. def to_app_model_url
  3. @to_app_model_url ||= begin
  4. to_s.gsub(/::/, '_')
  5. .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
  6. .gsub(/([a-z\d])([A-Z])/, '\1_\2')
  7. .tr('-', '_')
  8. .downcase
  9. end
  10. end
  11. def to_app_model
  12. @to_app_model ||= to_s.gsub(/::/, '').to_sym
  13. end
  14. end