When reading the ruby code
--Too little knowledge about the implicit part ――It's too complicated to understand
Sometimes I use a debugger.
However, in rare cases, I wanted to step in a method, but the description that I thought was an argument of that method was actually another method call, and I couldn't understand the call tree.
At that time, source_location that grows in class Method
I finally came up with the idea of using the method, so make a note of it.
When running rspec, I tried to replace the redis client used in ʻActiveSupport :: Cache :: RedisCacheStore with a mock, but there is no method called
with`, and an example of investigating the cause of the failure.
Line 345 becomes method_missing with redis.with.
Looking at the redis gem, it seems that with
is not defined.
I wonder what.
From: /bundle/gems/activesupport-6.0.3.2/lib/active_support/cache/redis_cache_store.rb:344 ActiveSupport::Cache::Strategy::LocalCache#read_entry:
339: # Store provider interface:
340: # Read an entry from the cache.
341: def read_entry(key, **options)
342: failsafe :read_entry do
343: binding.pry
=> 344: raw = options&.fetch(:raw, false)
345: deserialize_entry(redis.with { |c| c.get(key) }, raw: raw)
346: end
347: end
348:
349: def read_multi_entries(names, **options)
Stop replacing the mock, re-execute, and try to view the source.
[1] pry(#<ActiveSupport::Cache::RedisCacheStore>)> redis.method(:with).source
=> " def with\n yield self\n end\n"
What is this method?
In such a case, source_location
!
[2] pry(#<ActiveSupport::Cache::RedisCacheStore>)> redis.method(:with).source_location
=> ["/bundle/gems/activesupport-6.0.3.2/lib/active_support/cache/redis_cache_store.rb", 24]
Is it here? https://github.com/rails/rails/blob/fbe2433be6e052a1acac63c7faf287c52ed3c5ba/activesupport/lib/active_support/cache/redis_cache_store.rb#L24-L26
Is it easy to use by including ConnectionPoolLike
and patching Redis
?
I wonder if I have to include ConnectionPoolLike
in the redis client that I plug in with a mock.
If the implementation of ActiveSupport changes, I wonder if I can follow it properly.
Like.
Q
If classes are opened in various places and the behavior can be changed, it may be difficult to notice just by reading the source. Finished.