Sha256: 9c88a028c2d2ed2e9a5dd00894d2dd972a79ffe02589d20bb204173ec0b6b661
Contents?: true
Size: 650 Bytes
Versions: 15
Compression:
Stored size: 650 Bytes
Contents
class SiteHub module Memoize def memoize(*methods) methods.each do |method| method_alias = "_#{method}" alias_method method_alias, method define_memoized_method(method, method_alias) end end private def define_memoized_method(method, method_alias) define_method(method) do |*args, &block| attribute = "@#{method}".gsub('?', 'question_mark') return instance_variable_get(attribute) if instance_variable_defined? attribute send(method_alias, *args, &block).tap do |result| instance_variable_set(attribute, result) end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems