net_tcp_client
net_tcp_client copied to clipboard
ArgumentError with Ruby 3
I'm using version 2.2.1 of the gem with Ruby 3.1.2p20 in Debian Bookworm.
I'm getting ArgumentError when calling Net::TCPClient.connect(connection_params) because the parameters are passed to new in a way not compatible with Ruby 3:
From: /var/lib/gems/3.1.0/gems/net_tcp_client-2.2.1/lib/net/tcp_client/tcp_client.rb:91 Net::TCPClient.connect:
90: def self.connect(params = {})
=> 91: require 'pry'; binding.pry
92: connection = new(params)
93: yield(connection)
94: ensure
95: connection&.close
96: end
[1] pry(Net::TCPClient)> params
=> {:server=>"foobar:8080", :connect_timeout=>1, :connect_retry_count=>4, :connect_retry_interval=>1, :write_timeout=>2, :read_timeout=>23}
[2] pry(Net::TCPClient)> new(params)
ArgumentError: wrong number of arguments (given 1, expected 0)
With Ruby 3 it appears to be necessary to use the double splat operator: new(**params)
See e.g. https://stackoverflow.com/a/68450312.