memo_wise
memo_wise copied to clipboard
memo_wise raises error when memoizing a method in a module that's included in a class that overrides `initialize`
trafficstars
I might be using memo_wise incorrectly here.. but seeing some odd behavior when I memoize a method in a module that's included in a class that has an initialize method.
require 'memo_wise'
module ModuleMethods
prepend MemoWise
def a_module_method
self.class.name
end
memo_wise :a_module_method
end
# Works to call ClassWithoutInitializer.new.a_module_method
class ClassWithoutInitializer
include ModuleMethods
end
# Does not work to call ClassWithInitializer.new("thing").a_module_method
class ClassWithInitializer
include ModuleMethods
def initialize(name)
@name = name
end
end
# Works
puts ClassWithoutInitializer.new.a_module_method
# Does not Work
# memo_wise-1.7.0/lib/memo_wise.rb:183:in `a_module_method': undefined method `fetch' for nil:NilClass (NoMethodError)
puts ClassWithInitializer.new("name").a_module_method
https://github.com/panorama-ed/memo_wise/pull/321 seems to fix the issue for us.