dry-core
dry-core copied to clipboard
! Fix class including a module with Memoizable raises error
My project uses "concern module pattern"
e.g. multiple controller classes including concern modules with instance methods cached
I am switching from memoist since it's officially unmaintained
Excuse my ignorance but what is "concern module pattern"? :) Why is this patch needed? At first glance, I don't feel comfortable with having a workaround for a misused ruby API.
A brief example:
require "dry/core/memoizable"
module WithBotDetection
include Dry::Core::Memoizable
def self.included(base)
# Do something custom
end
def is_bot?(something = false)
# ...
end
memoize :is_bot?
end
class Controller1
include WithBotDetection
end
class Controller2
include WithBotDetection
end
Controller1.new.is_bot? # => NoMethodError: undefined method `key?' for nil:NilClass
Due to #61 only happens to methods with arguments
More about "concern module pattern": https://api.rubyonrails.org/classes/ActiveSupport/Concern.html