Module: RuboCop::Isucon::MemorizeMethods
- Defined in:
- lib/rubocop/isucon/memorize_methods.rb
Overview
Memorize helper
Instance Method Summary collapse
-
#memorize(method_name) ⇒ Object
Define memorize method.
Instance Method Details
#memorize(method_name) ⇒ Object
Define memorize method
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubocop/isucon/memorize_methods.rb', line 23 def memorize(method_name) class_eval <<~RUBY, __FILE__, __LINE__ + 1 # def foo_with_cache # @foo_with_cache ||= foo_without_cache # end def #{method_name}_with_cache @#{method_name}_with_cache ||= #{method_name}_without_cache end RUBY alias_method :"#{method_name}_without_cache", method_name alias_method method_name, :"#{method_name}_with_cache" end |