dry-core icon indicating copy to clipboard operation
dry-core copied to clipboard

! Fix class including a module with Memoizable raises error

Open PikachuEXE opened this issue 4 years ago • 2 comments

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

PikachuEXE avatar Oct 08 '21 07:10 PikachuEXE

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.

flash-gordon avatar Oct 22 '21 12:10 flash-gordon

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

PikachuEXE avatar Oct 23 '21 04:10 PikachuEXE