lib/tacky.rb in tacky-0.3.1 vs lib/tacky.rb in tacky-0.3.2
- old
+ new
@@ -32,10 +32,13 @@
# Copyright:: Copyright (c) 2020 Yegor Bugayenko
# License:: MIT
class Tacky
undef_method :send
+ # Deep nesting will stop at these classes.
+ STOP = [Numeric, NilClass, TrueClass, FalseClass, Array, Hash].freeze
+
def initialize(origin, deep: false)
@origin = origin
@cache = {}
@deep = deep
@mutex = Mutex.new
@@ -45,10 +48,12 @@
@mutex.synchronize do
unless @cache.key?(args)
@cache[args] = @origin.__send__(*args) do |*a|
yield(*a) if block_given?
end
- @cache[args] = Tacky.new(@cache[args], deep: @deep) if @deep
+ if @deep && STOP.none? { |t| @cache[args].is_a?(t) }
+ @cache[args] = Tacky.new(@cache[args], deep: @deep)
+ end
end
@cache[args]
end
end