cache_method
cache_method copied to clipboard
Feature: cache method on any instance
I almost implemented this but found a quick way around it so wanted to get thoughts on the reasoning here.
Let's say you have an instance method you want to cache for all instances. For example, a class that computes a view:
class CrazyView
def make_it(objects)
...
end
cache_method :make_it
end
You have this instance in a few places in the app because this view is reused. There's no way to cache it across instances without wrapping it in a class method.
class CrazyView
class << self
def make_it(objects)
new.make_it(objects)
end
cache_method :make_it
end
def make_it(objects)
...
end
end