From 0512b5bfc93cf987b9267c2d1e5a975408ef8490 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 18 Nov 2022 22:40:03 +0000 Subject: [PATCH] About the Examples moved to separate file --- .gitignore | 1 - doc/net-http/examples.rdoc | 30 ++++++++++++++++++++++++++++++ lib/net/http.rb | 31 +------------------------------ lib/net/http/response.rb | 22 +--------------------- 4 files changed, 32 insertions(+), 52 deletions(-) create mode 100644 doc/net-http/examples.rdoc diff --git a/.gitignore b/.gitignore index 9106b2a3..bcf8cadc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ /.yardoc /_yardoc/ /coverage/ -/doc/ /pkg/ /spec/reports/ /tmp/ diff --git a/doc/net-http/examples.rdoc b/doc/net-http/examples.rdoc new file mode 100644 index 00000000..dd4acecd --- /dev/null +++ b/doc/net-http/examples.rdoc @@ -0,0 +1,30 @@ +Examples here assume that net/http has been required +(which also requires +uri+): + + require 'net/http' + +Many code examples here use these example websites: + +- https://jsonplaceholder.typicode.com. +- http://example.com. + +Some examples also assume these variables: + + uri = URI('https://jsonplaceholder.typicode.com') + uri.freeze # Examples may not modify. + hostname = uri.hostname # => "jsonplaceholder.typicode.com" + port = uri.port # => 443 + +So that example requests may be written as: + + Net::HTTP.get(uri) + Net::HTTP.get(hostname, '/index.html') + Net::HTTP.start(hostname) do |http| + http.get('/todos/1') + http.get('/todos/2') + end + +An example that needs a modified URI first duplicates +uri+, then modifies the duplicate: + + _uri = uri.dup + _uri.path = '/todos/1' diff --git a/lib/net/http.rb b/lib/net/http.rb index 03f158c2..fa21352f 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -98,36 +98,7 @@ class HTTPHeaderSyntaxError < StandardError; end # # == About the Examples # - # Examples here assume that net/http has been required - # (which also requires +uri+): - # - # require 'net/http' - # - # Many code examples here use these example websites: - # - # - https://jsonplaceholder.typicode.com. - # - http://example.com. - # - # Some examples also assume these variables: - # - # uri = URI('https://jsonplaceholder.typicode.com') - # uri.freeze # Examples may not modify. - # hostname = uri.hostname # => "jsonplaceholder.typicode.com" - # port = uri.port # => 443 - # - # So that example requests may be written as: - # - # Net::HTTP.get(uri) - # Net::HTTP.get(hostname, '/index.html') - # Net::HTTP.start(hostname) do |http| - # http.get('/todos/1') - # http.get('/todos/2') - # end - # - # An example that needs a modified URI first duplicates +uri+, then modifies: - # - # _uri = uri.dup - # _uri.path = '/todos/1' + # :include: doc/net-http/examples.rdoc # # == URIs # diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index 567b9573..83853ffd 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -4,27 +4,7 @@ # # == About the Examples # -# Examples here assume that net/http has been required -# (which also requires +uri+): -# -# require 'net/http' -# -# Many code examples here use these example websites: -# -# - https://jsonplaceholder.typicode.com. -# - http://example.com. -# -# Some examples also assume these variables: -# -# uri = URI('https://jsonplaceholder.typicode.com') -# uri.freeze # Examples may not modify. -# hostname = uri.hostname # => "jsonplaceholder.typicode.com" -# port = uri.port # => 443 -# -# An example that needs a modified URI first duplicates +uri+, then modifies: -# -# _uri = uri.dup -# _uri.path = '/todos/1' +# :include: doc/net-http/examples.rdoc # # == Returned Responses #