<commit_before>Rollbar.plugins.define('basic_socket') do
  load_on_demand

  dependency { !configuration.disable_core_monkey_patch }

  # Needed to avoid active_support (< 4.1.0) bug serializing JSONs
  dependency do
    defined?(ActiveSupport::VERSION::STRING) &&
      Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new('5.2.0')
  end

  execute do
    @original_as_json = ::BasicSocket.public_instance_method(:as_json)
    class BasicSocket # :nodoc:
      def as_json(_options = nil)
        {
          :value => inspect
        }
      end
    end
  end

  revert do
    ::BasicSocket.send(:define_method, :as_json, @original_as_json)
  end
end<commit_msg>use alias_method to replace #as_json temporarily<commit_after>Rollbar.plugins.define('basic_socket') do
  load_on_demand

  dependency { !configuration.disable_core_monkey_patch }

  # Needed to avoid active_support (< 4.1.0) bug serializing JSONs
  dependency do
    defined?(ActiveSupport::VERSION::STRING) &&
      Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new('5.2.0')
  end

  execute do
    class BasicSocket # :nodoc:
      def new_as_json(_options = nil)
        {
          :value => inspect
        }
      end
      # alias_method is recommended over alias when aliasing at runtime.
      # https://github.com/rubocop-hq/ruby-style-guide#alias-method
      alias_method :original_as_json, :as_json # rubocop:disable Style/Alias
      alias_method :as_json, :new_as_json # rubocop:disable Style/Alias
    end
  end

  revert do
    class BasicSocket # :nodoc:
      alias_method :as_json, :original_as_json # rubocop:disable Style/Alias
    end
  end
end
{'fraction_non_alphanumeric': 0.1021021021021021, 'fraction_numerical': 0.007207207207207207, 'mean_word_length': 3.4545454545454546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268211', 'n_tokens_mistral': 541, 'n_tokens_neox': 528, 'n_words': 110}