matthewrudy/memoist

Flush Memoized Class Methods

omgitsbillryan opened this issue · 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:
#54

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!

#67 merged
Can this be closed?

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 >