Sha256: 6c387cad4b767e9ad0f484378e289a8e7345f725386fcccadc4bc5caf3b53c14

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

# NOTE: why not `.prepend` ?
#  `prepend` in this case works incorrectly and sometimes this patch can not be correctly
#  injected to the original module and it's children ancestors (Ruby-specific behaviour of
#  module including and prepending).

# @api public
# @since 0.24.0
module PP::PPMethods
  # :nocov:
  def pp(obj)
    # If obj is a Delegator then use the object being delegated to for cycle
    # detection

    # NOTE: --- PATCH ---
    if defined?(::Delegator) and (
      begin
        (class << obj; self; end) <= ::Delegator # patch
      rescue ::TypeError
        obj.is_a?(::Delegator)
      end
    )
      obj = obj.__getobj__
    end # instead of: obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator)
    # NOTE:
    #  Old implementation can not be used with BasicObject instances
    #  (with Qonfig::Compacted in our case)
    # NOTE: --- PATCH ---

    if check_inspect_key(obj)
      group { obj.pretty_print_cycle self }
      return
    end

    begin
      push_inspect_key(obj)
      group { obj.pretty_print self }
    ensure
      pop_inspect_key(obj) unless PP.sharing_detection
    end
  end
  # :nocov:
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
qonfig-0.30.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.28.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.27.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.26.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.25.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.24.1 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb
qonfig-0.24.0 lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb