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

Calling memoize on methods whose names are certain symbols causes syntax errors #89

Open
patbl opened this issue Nov 25, 2020 · 1 comment

Comments

@patbl
Copy link

patbl commented Nov 25, 2020

For example:

require 'memoist'

class Foo
  extend Memoist

  def [](bar)
    rand
  end
  memoize :[]
end
[22:03:27] ~/projects  ➜ ruby brackets.rb
Traceback (most recent call last):
        8: from brackets.rb:3:in `<main>'
        7: from brackets.rb:9:in `<class:Foo>'
        6: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:127:in `memoize'
        5: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:127:in `each'
        4: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:131:in `block in memoize'
        3: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:55:in `memoist_eval'
        2: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:55:in `class_eval'
        1: from /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:205:in `block (2 levels) in memoize'
/Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:205:in `module_eval': /Users/pat/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/memoist-0.16.2/lib/memoist.rb:213: syntax error, unexpected '(', expecting `end' (SyntaxError)
...        value = _unmemoized_[](*args)
...                              ^

This is true also of methods such as +, +@, -, -@, &, |, etc.

@pboling
Copy link
Contributor

pboling commented Jun 4, 2024

FYI: Added this alert to the new memoist repo

Important

Recommendation

Consider using MemoWise instead, as it is maintained, fully tested, provides thread safety guarantees, and is much, much faster.

Other Alternatives

In case you need a tool with this feature set that is currently maintained, check out:

Tip

Seriously though, read the important note above.

Warning

If you must continue - be aware that this is unmaintained software.

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

2 participants