Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Net::HTTPSession#start
start() { |http| ... }
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/net/http.rb, line 1629
def start # :yield: http
raise IOError, 'HTTP session already opened' if @started
if block_given?
begin
do_start
return yield(self)
ensure
do_finish
end
end
do_start
self
end
Starts an HTTP session.
Without a block, returns self:
Example
http = Net::HTTP.new(hostname) # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.start # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=true> http.started? # => true http.finish
With a block, calls the block with self, finishes the session when the block exits, and returns the block’s value:
Example
http.start do |http| http end # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.started? # => false