Method: Gem::Net::HTTP#start
- Defined in:
- lib/rubygems/vendor/net-http/lib/net/http.rb
#start ⇒ Object
Starts an HTTP session.
Without a block, returns self
:
http = Gem::Net::HTTP.new(hostname)
# => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.start
# => #<Gem::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:
http.start do |http|
http
end
# => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.started? # => false
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'lib/rubygems/vendor/net-http/lib/net/http.rb', line 1627 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 |