Project

General

Profile

Actions

Bug #18792

closed

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

Added by rahulroot (Rahul Gupta) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
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) over 2 years 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) over 2 years ago

  • Status changed from Open to Rejected

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

Actions

Also available in: Atom PDF

Like0
Like0Like0