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

Flush Memoized Class Methods #63

Open
omgitsbillryan opened this issue Mar 15, 2017 · 3 comments
Open

Flush Memoized Class Methods #63

omgitsbillryan opened this issue Mar 15, 2017 · 3 comments

Comments

@omgitsbillryan
Copy link

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

@RogerPodacter
Copy link

RogerPodacter commented Apr 15, 2017

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!

@PikachuEXE
Copy link
Contributor

#67 merged
Can this be closed?

@omgitsbillryan
Copy link
Author

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 >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants