lib/memo_wise.rb in memo_wise-1.7.0 vs lib/memo_wise.rb in memo_wise-1.8.0

- old
+ new

@@ -1,8 +1,9 @@ # frozen_string_literal: true -require "set" +# Disable RuboCop here because Ruby < 3.2 does not load `set` by default. +require "set" # rubocop:disable Lint/RedundantRequireStatement require "memo_wise/internal_api" require "memo_wise/version" # MemoWise is the wise choice for memoization in Ruby. @@ -28,16 +29,16 @@ module MemoWise # Constructor to set up memoization state before # [calling the original](https://medium.com/@jeremy_96642/ruby-method-auditing-using-module-prepend-4f4e69aacd95) # constructor. # - # - **Q:** Why is [Module#prepend](https://ruby-doc.org/core-3.1.0/Module.html#method-i-prepend) + # - **Q:** Why is [Module#prepend](https://ruby-doc.org/3.2.1/Module.html#method-i-prepend) # important here # ([more info](https://medium.com/@leo_hetsch/ruby-modules-include-vs-prepend-vs-extend-f09837a5b073))? # - **A:** To set up *mutable state* inside the instance, even if the original # constructor will then call - # [Object#freeze](https://ruby-doc.org/core-3.1.0/Object.html#method-i-freeze). + # [Object#freeze](https://ruby-doc.org/3.2.1/Object.html#method-i-freeze). # # This approach supports memoization on frozen (immutable) objects -- for # example, classes created by the # [Values](https://github.com/tcrayford/Values) # [gem](https://rubygems.org/gems/values). @@ -82,11 +83,11 @@ # Private setup method, called automatically by `prepend MemoWise` in a class. # # @param target [Class] # The `Class` into to prepend the MemoWise methods e.g. `memo_wise` # - # @see https://ruby-doc.org/core-3.1.0/Module.html#method-i-prepended + # @see https://ruby-doc.org/3.2.1/Module.html#method-i-prepend # # @example # class Example # prepend MemoWise # end @@ -97,11 +98,11 @@ # [calling the original](https://medium.com/@jeremy_96642/ruby-method-auditing-using-module-prepend-4f4e69aacd95) # allocator. # # This is necessary in addition to the `#initialize` method definition # above because - # [`Class#allocate`](https://ruby-doc.org/core-3.1.0/Class.html#method-i-allocate) + # [`Class#allocate`](https://ruby-doc.org/3.2.1/Class.html#method-i-allocate) # bypasses `#initialize`, and when it's used (e.g., # [in ActiveRecord](https://github.com/rails/rails/blob/a395c3a6af1e079740e7a28994d77c8baadd2a9d/activerecord/lib/active_record/persistence.rb#L411)) # we still need to be able to access MemoWise's instance variable. Despite # Ruby documentation indicating otherwise, `Class#new` does not call # `Class#allocate`, so we need to override both. @@ -252,10 +253,10 @@ method_name, MemoWise.instance_method(method_name) ) end - # Override [Module#instance_method](https://ruby-doc.org/core-3.1.0/Module.html#method-i-instance_method) + # Override [Module#instance_method](https://ruby-doc.org/3.2.1/Module.html#method-i-instance_method) # to proxy the original `UnboundMethod#parameters` results. We want the # parameters to reflect the original method in order to support callers # who want to use Ruby reflection to process the method parameters, # because our overridden `#initialize` method, and in some cases the # generated memoized methods, will have a generic set of parameters