Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memo_wise raises error when memoizing a method in a module that's included in a class that overrides initialize #302

Open
joevandyk opened this issue Mar 15, 2023 · 1 comment · May be fixed by #321 or #327

Comments

@joevandyk
Copy link

joevandyk commented Mar 15, 2023

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
@joevandyk joevandyk linked a pull request Oct 31, 2023 that will close this issue
2 tasks
@joevandyk
Copy link
Author

#321 seems to fix the issue for us.

JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
JacobEvelyn added a commit that referenced this issue Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant