@@ -448,18 +448,28 @@ class << self
448448 #
449449 # Creates a new instance of SSLSocket.
450450 # _remote\_host_ and _remote_port_ are used to open TCPSocket.
451- # If _context_ is provided,
452- # the SSL Sockets initial params will be taken from the context.
453451 # If _local\_host_ and _local\_port_ are specified,
454452 # then those parameters are used on the local end to establish the connection.
453+ # If _context_ is provided,
454+ # the SSL Sockets initial params will be taken from the context.
455455 #
456- # === Example
457- # ctx = OpenSSL::SSL::SSLContext.new
458- # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, ctx )
456+ # === Examples
457+ #
458+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
459459 # sock.connect # Initiates a connection to localhost:443
460- def open ( remote_host , remote_port , context = nil , local_host = nil , local_port = nil )
460+ #
461+ # with SSLContext:
462+ #
463+ # ctx = OpenSSL::SSL::SSLContext.new
464+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
465+ # sock.connect # Initiates a connection to localhost:443 with SSLContext
466+ def open ( remote_host , remote_port , local_host = nil , local_port = nil , context : nil )
461467 sock = ::TCPSocket . open ( remote_host , remote_port , local_host , local_port )
462- OpenSSL ::SSL ::SSLSocket . new ( sock , context )
468+ if context . nil?
469+ return OpenSSL ::SSL ::SSLSocket . new ( sock )
470+ else
471+ return OpenSSL ::SSL ::SSLSocket . new ( sock , context )
472+ end
463473 end
464474 end
465475 end
0 commit comments