Refactoring: Improving performance by memorizing app_model string generation.

This commit is contained in:
Thorsten Eckel 2018-12-22 15:43:03 +01:00
parent 197ecade07
commit b361b43836

View file

@ -1,15 +1,15 @@
class Class
def to_app_model_url
camel_cased_word = 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
@to_app_model_url ||= begin
to_s.gsub(/::/, '_')
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr('-', '_')
.downcase
end
end
def to_app_model
camel_cased_word = to_s
camel_cased_word.gsub(/::/, '').to_sym
@to_app_model ||= to_s.gsub(/::/, '').to_sym
end
end