Creates a new string of the given length and yields a zero-copy IO::Buffer
instance to the block which uses the string as a source. The block is expected to write to the buffer and the string will be returned.
IO::Buffer.string(4) do |buffer| buffer.set_string("Ruby") end # => "Ruby"
Create an IO::Buffer
for reading from file
by memory-mapping the file. file_io
should be a File
instance, opened for reading.
Optional size
and offset
of mapping can be specified.
By default, the buffer would be immutable (read only); to create a writable mapping, you need to open a file in read-write mode, and explicitly pass flags
argument without IO::Buffer::IMMUTABLE.
File.write('test.txt', 'test') buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY) # => #<IO::Buffer 0x00000001014a0000+4 MAPPED READONLY> buffer.readonly? # => true buffer.get_string # => "test" buffer.set_string('b', 0) # `set_string': Buffer is not writable! (IO::Buffer::AccessError) # create read/write mapping: length 4 bytes, offset 0, flags 0 buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 4, 0) buffer.set_string('b', 0) # => 1 # Check it File.read('test.txt') # => "best"
Note that some operating systems may not have cache coherency between mapped buffers and file reads.
Inspect the buffer and report useful information about it’s internal state. Only a limited portion of the buffer will be displayed in a hexdump style format.
buffer = IO::Buffer.for("Hello World") puts buffer.inspect # #<IO::Buffer 0x000000010198ccd8+11 EXTERNAL READONLY SLICE> # 0x00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello World
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 mapped, meaning it references memory mapped by the buffer.
Mapped buffers are either anonymous, if created by ::new
with the IO::Buffer::MAPPED
flag or if the size was at least IO::Buffer::PAGE_SIZE
, or backed by a file if created with ::map
.
Mapped buffers can usually be resized, and such an operation will typically invalidate all slices, but not always.
Returns a human-readable string representation of this instruction sequence, including the label
and path
.
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.
A summary of cookie string.
Returns a string representation of self
:
Net::HTTP.new(hostname).inspect # => "#<Net::HTTP jsonplaceholder.typicode.com:80 open=false>"
Finishes the HTTP session:
http = Net::HTTP.new(hostname) http.start http.started? # => true http.finish # => nil http.started? # => false
Raises IOError
if not in a session.
Sends a PROPFIND request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Propfind
object created from string path
, string body
, and initial headers hash initheader
.
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.propfind('/todos/1', data)
Returns a string representation of the request:
Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
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"
Completion
for hash key.
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String