dkubb / memoizable Goto Github PK
View Code? Open in Web Editor NEWMemoize method return values
License: MIT License
Memoize method return values
License: MIT License
Query List: ["memoizable"]
Query Gemcutter Dependency Endpoint API: memoizable
HTTP GET https://gems.ruby-china.com/api/v1/dependencies?gems=memoizable
HTTP 200 OK https://gems.ruby-china.com/api/v1/dependencies?gems=memoizable
Query List: []
Resolving dependencies....
ruby_dep-1.5.0 requires ruby version ~> 2.2, >= 2.2.5, which is incompatible with the current version, ruby 3.0.3p157
Bundler::InstallError: ruby_dep-1.5.0 requires ruby version ~> 2.2, >= 2.2.5, which is incompatible with the current version, ruby 3.0.3p157
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:249:in `block in ensure_specs_are_compatible!'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/spec_set.rb:136:in `each'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/spec_set.rb:136:in `each'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:246:in `ensure_specs_are_compatible!'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:83:in `block in run'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:12:in `block in lock'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:9:in `open'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/process_lock.rb:9:in `lock'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:71:in `run'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/installer.rb:23:in `install'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli/install.rb:60:in `run'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:253:in `block in install'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/settings.rb:131:in `temporary'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:252:in `install'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:31:in `dispatch'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/cli.rb:25:in `start'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.32/libexec/bundle:49:in `block in <top (required)>'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/home/siwei/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.32/libexec/bundle:37:in `<top (required)>'
/home/siwei/.asdf/installs/ruby/3.0.3/bin/bundle:23:in `load'
/home/siwei/.asdf/installs/ruby/3.0.3/bin/bundle:23:in `<main>'
require 'memoizable'
class A
include Memoizable
def foo
:foo
end
memoize :foo
end
class B < A
def foo
super
end
memoize :foo
end
B.new.foo
Results in:
/home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:48:in `[]=': The method foo is already memoized (ArgumentError)
from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
from /home/mbj/.gem/ruby/2.1.0/gems/thread_safe-0.1.3/lib/thread_safe/cache.rb:51:in `fetch'
from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
from /home/mbj/.rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:61:in `block in fetch'
from /home/mbj/.gem/ruby/2.1.0/gems/thread_safe-0.1.3/lib/thread_safe/cache.rb:51:in `fetch'
from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/memory.rb:60:in `fetch'
from /home/mbj/.gem/ruby/2.1.0/gems/memoizable-0.4.0/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
from repro.rb:17:in `<main>'
Root cause: Memory#[]=
gets hit twice and the memory rightfully raises here.
IMHO we should detect this situation when overriding the memoizer in parent class.
Hello,
I wanted to make memoize
available across the project and I came up with this:
Class.class_eval do
def memoize *args
include ::Memoizable
memoize *args
end
end
But that's a bit ugly solution so just wanted to ask how would you recommend achieving this?
Latest rails depends on thread_safe ~> 0.3.1 - please bump it here and push a release. Pretty please 😄
Hello.
I just finished publishing https://github.com/KoanHealth/forget-me-not. While tipping the hat to @sferik, he pointed me to this gem. I agree with him that the world doesn't need these ideas developed in two places, so I'd like to offer to help in any way that I can.
Two things that I incorporated into forget-me-not are arguments and caching.
Arguments are pretty straightforward.
Caching is intended to be more of a system wide memoization. We started from @sferik's code to enable some classes that chew on aggregate medical claims data to share the results of their initial queries.
My big question is can these two ideas find a home in this gem?
".rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call': [DEPRECATION] #verified is deprecated. Use #verified? instead."
I don'y have the memoizable gem within my project so I'm not sure what might be generating the warning.
My rake task still runs - it's just outputting this message for each record I process.
I'm running Rails 4.1.4 and using Postgres for my database.
One thing that got lost in the hubbub over memoizing methods with arguments was the caching capability in forget-me-not which has a similar interface (even if the intent is wildly different).
I know this is a somewhat odd fit in a project called memoizable, but the two ideas occupy a similar region of headspace, so I thought it made sense to combine them in a single gem.
There's a pretty decent write-up of the intent and capabilities of cacheable on the forget-me-not project page. Is it possible that this idea can find a home here?
I was messing around in irb
(actually, pry
) and felt 😕 when I attempted to memoize a method outside of a class context:
[1] pry(main)> require 'memoizable'
=> true
[2] pry(main)> include Memoizable
=> Object
[3] pry(main)> def foo; end
=> nil
[4] pry(main)> memoize :foo
NoMethodError: undefined method `each' for :foo:Symbol
from /Users/e/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/memoizable-0.2.0/lib/memoizable/memory.rb:59:in `set'
This is the line where the error is occurring, which I believe is being called from here.
This error occurs when attempting to memoize singleton methods, defined on an instance of a class:
require 'memoizable'
class Foo
include Memoizable
end
foo = Foo.new
def foo.bar; end
foo.memoize :bar
To resolve this issue we must first address the following question: Should one be able to memoize singleton methods?
If the answer is “yes”, resolving this issue entails adding that feature.
If the answer is “no”, we can just raise a better error message.
I noticed a massive slow down in ROM after upgrading to latest adamantium/memoizable. Do you guys think some recent changes may affect performance (ThreadSafe maybe?).
See discussion here: #4 (comment)
Consider the following code:
class Foo
def bar
yield
end
memoize :bar
def baz
yield if block_given?
end
memoize :baz
end
Currently, if a user memoizes a method with an explicit block (or any explicit parameters), they will receive an error at load time (Memoizable::MethodBuilder::InvalidArityError
). However, if a method yields to an implicit block, users will receive a LocalJumpError
(in the case of bar
) or—worse—no error at all (in the case of baz
). This behavior may surprise users, who don’t expect memoize
to modify the behavior of their methods.
This seems bad but I can’t think of a good solution so I’m opening this issue for discussion. Curious to hear your thoughts…
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.