Returns an Array
with 14 elements representing the instruction sequence with the following data:
A string identifying the data format. Always YARVInstructionSequence/SimpleDataFormat
.
The major version of the instruction sequence.
The minor version of the instruction sequence.
A number identifying the data format. Always 1.
A hash containing:
:arg_size
the total number of arguments taken by the method or the block (0 if iseq doesn’t represent a method or block)
:local_size
the number of local variables + 1
:stack_max
used in calculating the stack depth at which a SystemStackError
is thrown.
label
The name of the context (block, method, class, module, etc.) that this instruction sequence belongs to.
<main>
if it’s at the top level, <compiled>
if it was evaluated from a string.
path
The relative path to the Ruby file where the instruction sequence was loaded from.
<compiled>
if the iseq was evaluated from a string.
absolute_path
The absolute path to the Ruby file where the instruction sequence was loaded from.
nil
if the iseq was evaluated from a string.
first_lineno
The number of the first source line where the instruction sequence was loaded from.
The type of the instruction sequence.
Valid values are :top
, :method
, :block
, :class
, :rescue
, :ensure
, :eval
, :main
, and plain
.
An array containing the names of all arguments and local variables as symbols.
An Hash
object containing parameter information.
More info about these values can be found in vm_core.h
.
A list of exceptions and control flow operators (rescue, next, redo, break, etc.).
An array of arrays containing the instruction names and operands that make up the body of the instruction sequence.
Note that this format is MRI specific and version dependent.
Returns the contents of this Tms
object as a formatted string, according to a format
string like that passed to Kernel.format
. In addition, format
accepts the following extensions:
%u
Replaced by the user CPU time, as reported by Tms#utime
.
%y
Replaced by the system CPU time, as reported by stime
(Mnemonic: y of “s*y*stem”)
%U
Replaced by the children’s user CPU time, as reported by Tms#cutime
%Y
Replaced by the children’s system CPU time, as reported by Tms#cstime
%t
Replaced by the total CPU time, as reported by Tms#total
%r
Replaced by the elapsed real time, as reported by Tms#real
%n
Replaced by the label string, as reported by Tms#label
(Mnemonic: n of “*n*ame”)
If format
is not given, FORMAT
is used as default value, detailing the user, system and real elapsed time.
Same as format
.
Returns a new 6-element array, consisting of the label, user CPU time, system CPU time, children’s user CPU time, children’s system CPU time and elapsed real time.
Returns a hash containing the same data as ‘to_a`.
Convert the Cookie
to its string representation.
Posts data to a host; returns a Net::HTTPResponse
object.
Argument url
must be a URL; argument data
must be a string:
_uri = uri.dup _uri.path = '/posts' data = '{"title": "foo", "body": "bar", "userId": 1}' headers = {'content-type': 'application/json'} res = Net::HTTP.post(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true> puts res.body
Output:
{ "title": "foo", "body": "bar", "userId": 1, "id": 101 }
Related:
Net::HTTP::Post
: request class for HTTP method POST
.
Net::HTTP#post
: convenience method for HTTP method POST
.
Creates a new Net::HTTP object, http
, via Net::HTTP.new:
For arguments address
and port
, see Net::HTTP.new
.
For proxy-defining arguments p_addr
through p_pass
, see Proxy Server.
For argument opts
, see below.
With no block given:
Calls http.start
with no block (see start
), which opens a TCP connection and HTTP session.
Returns http
.
The caller should call finish
to close the session:
http = Net::HTTP.start(hostname) http.started? # => true http.finish http.started? # => false
With a block given:
Calls http.start
with the block (see start
), which:
Opens a TCP connection and HTTP session.
Calls the block, which may make any number of requests to the host.
Closes the HTTP session and TCP connection on block exit.
Returns the block’s value object
.
Returns object
.
Example:
hostname = 'jsonplaceholder.typicode.com' Net::HTTP.start(hostname) do |http| puts http.get('/todos/1').body puts http.get('/todos/2').body end
Output:
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false } { "userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false }
If the last argument given is a hash, it is the opts
hash, where each key is a method or accessor to be called, and its value is the value to be set.
The keys may include:
Note: If port
is nil
and opts[:use_ssl]
is a truthy value, the value passed to new
is Net::HTTP.https_default_port
, not port
.
Returns true
if the HTTP session has been started:
http = Net::HTTP.new(hostname) http.started? # => false http.start http.started? # => true http.finish # => nil http.started? # => false Net::HTTP.start(hostname) do |http| http.started? end # => true http.started? # => false
Starts an HTTP session.
Without a block, returns self
:
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:
http.start do |http| http end # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.started? # => false
Sends a POST request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With a block given, calls the block with the response body:
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.post('/todos', data) do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\",\n \"id\": 201\n}"
With no block given, simply returns the response object:
http.post('/todos', data) # => #<Net::HTTPCreated 201 Created readbody=true>
Related:
Net::HTTP::Post
: request class for HTTP method POST.
Net::HTTP.post
: sends POST request, returns response body.
Posts data to a host; returns a Net::HTTPResponse
object.
Argument url
must be a URL; argument data
must be a string:
_uri = uri.dup _uri.path = '/posts' data = '{"title": "foo", "body": "bar", "userId": 1}' headers = {'content-type': 'application/json'} res = Net::HTTP.post(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true> puts res.body
Output:
{ "title": "foo", "body": "bar", "userId": 1, "id": 101 }
Related:
Net::HTTP::Post
: request class for HTTP method POST
.
Net::HTTP#post
: convenience method for HTTP method POST
.
Creates a new Net::HTTP object, http
, via Net::HTTP.new:
For arguments address
and port
, see Net::HTTP.new
.
For proxy-defining arguments p_addr
through p_pass
, see Proxy Server.
For argument opts
, see below.
With no block given:
Calls http.start
with no block (see start
), which opens a TCP connection and HTTP session.
Returns http
.
The caller should call finish
to close the session:
http = Net::HTTP.start(hostname) http.started? # => true http.finish http.started? # => false
With a block given:
Calls http.start
with the block (see start
), which:
Opens a TCP connection and HTTP session.
Calls the block, which may make any number of requests to the host.
Closes the HTTP session and TCP connection on block exit.
Returns the block’s value object
.
Returns object
.
Example:
hostname = 'jsonplaceholder.typicode.com' Net::HTTP.start(hostname) do |http| puts http.get('/todos/1').body puts http.get('/todos/2').body end
Output:
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false } { "userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false }
If the last argument given is a hash, it is the opts
hash, where each key is a method or accessor to be called, and its value is the value to be set.
The keys may include:
Note: If port
is nil
and opts[:use_ssl]
is a truthy value, the value passed to new
is Net::HTTP.https_default_port
, not port
.
Returns true
if the HTTP session has been started:
http = Net::HTTP.new(hostname) http.started? # => false http.start http.started? # => true http.finish # => nil http.started? # => false Net::HTTP.start(hostname) do |http| http.started? end # => true http.started? # => false
Starts an HTTP session.
Without a block, returns self
:
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:
http.start do |http| http end # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false> http.started? # => false
Sends a POST request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With a block given, calls the block with the response body:
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.post('/todos', data) do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\",\n \"id\": 201\n}"
With no block given, simply returns the response object:
http.post('/todos', data) # => #<Net::HTTPCreated 201 Created readbody=true>
Related:
Net::HTTP::Post
: request class for HTTP method POST.
Net::HTTP.post
: sends POST request, returns response body.
Returns the authority for an HTTP
uri, as defined in www.rfc-editor.org/rfc/rfc3986#section-3.2.
Example:
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"
Returns the origin for an HTTP
uri, as defined in www.rfc-editor.org/rfc/rfc6454.
Example:
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').origin #=> "http://www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').origin #=> "http://www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').origin #=> "http://www.example.com" URI::HTTPS.build(host: 'www.example.com', path: '/foo/bar').origin #=> "https://www.example.com"
Appends sep
to the text to be output. By default sep
is ‘ ’
width
argument is here for compatibility. It is a noop argument.
This is used as a predicate, and ought to be called first.