memoist icon indicating copy to clipboard operation
memoist copied to clipboard

Flush Memoized Class Methods

Open omgitsbillryan opened this issue 7 years ago • 3 comments

Given a class:

  class Foo
    class << self
      extend Memoist

      def bar
        "hello"
      end
      memoize :bar

    end
  end

Foo.flush_cache spits out:

NoMethodError: undefined method `all_memoized_structs' for Foo:Class

I also found this related issue: https://github.com/matthewrudy/memoist/issues/54

omgitsbillryan avatar Mar 15 '17 19:03 omgitsbillryan

FWIW you can hack around this with something like Foo.remove_instance_variable(:@_memoized_bar).

Not pretty but half a loaf is better than none!

RogerPodacter avatar Apr 15 '17 18:04 RogerPodacter

#67 merged Can this be closed?

PikachuEXE avatar Jun 21 '17 01:06 PikachuEXE

I believe so. Just ran a manual test:

2.3.0 :001 >   class Foo
2.3.0 :002?>       class << self
2.3.0 :003?>           extend Memoist
2.3.0 :004?>     
2.3.0 :005 >             def bar
2.3.0 :006?>               "hello"
2.3.0 :007?>             end
2.3.0 :008?>           memoize :bar
2.3.0 :009?>     
2.3.0 :010 >           end
2.3.0 :011?>     end
 => :bar 
2.3.0 :012 > Foo.bar
 => "hello" 
2.3.0 :013 > Foo.flush_cache
 => [#<struct Memoist::MemoizedMethod memoized_method=:bar, ivar="@_memoized_bar", arity=0>] 
2.3.0 :014 >

omgitsbillryan avatar Aug 10 '17 16:08 omgitsbillryan