If the buffer was freed with free
, transferred with transfer
, or was never allocated in the first place.
buffer = IO::Buffer.new(0) buffer.null? #=> true buffer = IO::Buffer.new(4) buffer.null? #=> false buffer.free buffer.null? #=> true
The buffer is external if it references the memory which is not allocated or mapped by the buffer itself.
A buffer created using ::for
has an external reference to the string’s memory.
External buffer can’t be resized.
If the buffer is internal, meaning it references memory allocated by the buffer itself.
An internal buffer is not associated with any external memory (e.g. string) or file mapping.
Internal buffers are created using ::new
and is the default when the requested size is less than the IO::Buffer::PAGE_SIZE
and it was not requested to be mapped on creation.
Internal buffers can be resized, and such an operation will typically invalidate all slices, but not always.
If the buffer is read only, meaning the buffer cannot be modified using set_value
, set_string
or copy
and similar.
Frozen strings and read-only files create read-only buffers.
Returns an array of values of buffer_type
starting from offset
.
If count
is given, only count
values will be returned.
IO::Buffer.for("Hello World").values(:U8, 2, 2) # => [108, 108]
Evaluates the instruction sequence and returns the result.
RubyVM::InstructionSequence.compile("1 + 2").eval #=> 3
Returns the value or list of values for this cookie.
Replaces the value of this cookie with a new value or list of values.
Is this server alive?
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
Raises an HTTP error if the response is not 2xx (success).
def equal: () -> String
?
Returns the value of the node as a Ruby Float
.
Returns the value of the node as a Ruby Complex
.
def decimal?: () -> bool
def hexadecimal?: () -> bool
Returns the value of the node as a Ruby Integer
.
Returns the value of the node as a Ruby Rational
.