<commit_before>require 'socket'

# support unixsocket to tcp only supproted library.
# @example
#   require 'unix_socket_hack'
#   UNIXSocketHack.apply({ 'unixsocket:9999' => '/path/to/unix.sock' })
#   sock = TCPSocket.new('unixsocket', 9999)
#   #=> UNIXSocket
#
class UNIXSocketHack
  def self.apply(mapping)
    TCPSocket.singleton_class.class_eval do
      alias_method :new_without_unixsockhack, :new

      define_method(:new_with_unixsockhack) do |host,service|
        if val = mapping[[host, service].join(":")]
          return UNIXSocket.new(val)
        else
          return new_without_unixsockhack(host, service)
        end
      end<commit_msg>support 3 or 4 args.<commit_after>require 'socket'

# support unixsocket to tcp only supproted library.
# @example
#   require 'unix_socket_hack'
#   UNIXSocketHack.apply({ 'unixsocket:9999' => '/path/to/unix.sock' })
#   sock = TCPSocket.new('unixsocket', 9999)
#   #=> UNIXSocket
#
class UNIXSocketHack
  def self.apply(mapping)
    TCPSocket.singleton_class.class_eval do
      alias_method :new_without_unixsockhack, :new

      define_method(:new_with_unixsockhack) do |remote_host, remote_port, local_host=nil, local_port=nil|
        if val = mapping[[remote_host, remote_port].join(":")]
          return UNIXSocket.new(val)
        else
          return new_without_unixsockhack(remote_host, remote_port, local_host, local_port)
        end
      end
{'fraction_non_alphanumeric': 0.10907811400422238, 'fraction_numerical': 0.012667135819845179, 'mean_word_length': 3.7558528428093645, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5735744', 'n_tokens_mistral': 499, 'n_tokens_neox': 486, 'n_words': 94}