kklimuk / ruby_memoized Goto Github PK
View Code? Open in Web Editor NEWMemoize method return values even with different arguments.
License: MIT License
Memoize method return values even with different arguments.
License: MIT License
Hi kklimuk,
Thanks for your awesome blog post and this nifty piece of software.
I've been solving this problem countless times as well. I like your implementation! Specifically because you can just toggle it on and off where you like.
The issue I have is minor and I see why it happens. When I memoize a method that does not have arguments, it doesn't work, see example:
require 'ruby_memoized'
class MyExample
include RubyMemoized
memoized
def hello
puts "hello world"
end
end
MyExample.new.hello
Output:
$ ruby test_memoization.rb
Traceback (most recent call last):
3: from test_memoization.rb:13:in `<main>'
2: from /home/tom/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ruby_memoized-0.1.3/lib/ruby_memoized.rb:37:in `block in method_added'
1: from /home/tom/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ruby_memoized-0.1.3/lib/ruby_memoized/memoizer.rb:12:in `call'
test_memoization.rb:8:in `hello': wrong number of arguments (given 1, expected 0) (ArgumentError)
I understand it has to do with your scoped support. It would be great if this could be solved or if another memoization method could be added for this scenario.
Thanks for the big explanation. I can definitely use your code to implement exactly what I need, but maybe ruby_memoized could be even better (imho).
Kind regards,
TvL2386
Hi @kklimuk -- really appreciate this utility / gem. I am attempting an upgrade to Ruby 2.7 in my own projects and receive a deprecation warning from the gem of:
ruby_memoized-0.1.2/lib/ruby_memoized/memoizer.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
I'm not sure if you've seen it already or read the Ruby 2.7 deprecation announcement regarding the keyword args. I found this blog post helpful when upgrading our codebase: https://blog.bigbinary.com/2020/04/14/ruby-2-7-deprecates-conversion-of-keyword-arguments.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.