memery
memery copied to clipboard
debug with memery
code:
require "memery"
require "pry"
class A
include Memery
memoize def test
end
end
a = A.new
binding.pry
and in pry execute $ a.test
current behavior:
> $ a.test
From: .../.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/memery-1.3.0/lib/memery.rb:58:
Owner: #<Module:0x000055b9f6294130>
Visibility: public
Signature: test(*args, &block)
Number of lines: 17
define_method method_name do |*args, &block|
if block || (condition && !instance_exec(&condition))
return super(*args, &block)
end
store = (@_memery_memoized_values ||= {})[method_key] ||= {}
if store.key?(args) &&
(ttl.nil? || Memery.monotonic_clock <= store[args][:time] + ttl)
return store[args][:result]
end
result = super(*args)
@_memery_memoized_values[method_key][args] =
{ result: result, time: Memery.monotonic_clock }
result
end
preferred behavior:
> $ a.test
From: test.rb:6:
Owner: A
Visibility: public
Signature: test()
Number of lines: 2
def test
end
Is it possible?
Try to add -s (read help for more information).
-s doesn't work (see https://github.com/pry/pry/issues/1756)
-sdoesn't work (see pry/pry#1756)
Oh, yes, sorry.
Then you can read my own example in https://github.com/tycooon/memery/pull/1#issuecomment-575180261 and try alternative approach (with the same code and module names) via https://github.com/AlexWayfer/alt_memery
There is instruction how to check source code of original method in native Ruby and with pry-byebug.