Project

General

Profile

Actions

Bug #18792

closed

Socket.tcp throws `getaddrinfo': no implicit conversion of Hash into String

Added by rahulroot (Rahul Gupta) about 2 months ago. Updated about 2 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
[ruby-core:108635]

Description

Hello,

I was using ruby 2.5.3 for a while, but now it's EOL, trying to port my code to ruby 3.0.4.
Same piece of code is throwing error on below code snippet.

Below piece of code works fine on ruby 2.5.3, but throws error on ruby 3.0.4.
I investigated socket.rb, it turns out that local_host is Hash in latest ruby, in older version it was NilClass.

I have a sample running application on local VM.

require 'socket'

host = "192.168.56.100"
port = 8081
socket_opts = {
   connect_timeout: 10,
}

Socket.tcp(host, port, socket_opts)

Updated by midnight (Sarun R) about 2 months ago

It's the Ruby 3 things. They don't try to match method parameters for you anymore.

You have to do it explicitly:

Socket.tcp(host, port, **socket_opts)

Updated by byroot (Jean Boussier) about 2 months ago

  • Status changed from Open to Rejected

Yes, it's a keyword argument, not an option hash.

Actions

Also available in: Atom PDF