Same as IO
.
See Zlib::GzipReader
documentation for a description.
Returns true
if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
Returns true
if the file is a character device, false
if it isn’t or if the operating system doesn’t support this feature.
File.stat("/dev/tty").chardev? #=> true
If the buffer is shared, meaning it references memory that can be shared with other processes (and thus might change without being modified locally).
# Create a test file: File.write('test.txt', 'test') # Create a shared mapping from the given file, the file must be opened in # read-write mode unless we also specify IO::Buffer::READONLY: buffer = IO::Buffer.map(File.open('test.txt', 'r+'), nil, 0) # => #<IO::Buffer 0x00007f1bffd5e000+4 EXTERNAL MAPPED SHARED> # Write to the buffer, which will modify the mapped file: buffer.set_string('b', 0) # => 1 # The file itself is modified: File.read('test.txt') # => "best"
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.
Fill buffer with value
, starting with offset
and going for length
bytes.
buffer = IO::Buffer.for('test').dup # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 74 65 73 74 test buffer.clear # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 00 00 00 00 .... buf.clear(1) # fill with 1 # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 01 01 01 .... buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 02 02 01 .... buffer.clear(2, 1) # fill with 2, starting from offset 1 # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 02 02 02 ....
Write at least length
bytes from the buffer starting at offset
, into the io
. If an error occurs, return -errno
.
If length
is not given or nil
, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.
If length
is zero, exactly one write
operation will occur.
If offset
is not given, it defaults to zero, i.e. the beginning of the buffer.
out = File.open('output.txt', 'wb') IO::Buffer.for('1234567').write(out, 3)
This leads to 123
being written into output.txt
Write at least length
bytes from the buffer starting at offset
, into the io
starting at the specified from
position. If an error occurs, return -errno
.
If length
is not given or nil
, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.
If length
is zero, exactly one pwrite
operation will occur.
If offset
is not given, it defaults to zero, i.e. the beginning of the buffer.
If the from
position is beyond the end of the file, the gap will be filled with null (0 value) bytes.
out = File.open('output.txt', File::RDWR) # open for read/write, no truncation IO::Buffer.for('1234567').pwrite(out, 2, 3, 1)
This leads to 234
(3 bytes, starting from position 1) being written into output.txt
, starting from file position 2.
Returns the path of this instruction sequence.
<compiled>
if the iseq was evaluated from a string.
For example, using irb:
iseq = RubyVM::InstructionSequence.compile('num = 1 + 2') #=> <RubyVM::InstructionSequence:<compiled>@<compiled>> iseq.path #=> "<compiled>"
Using ::compile_file
:
# /tmp/method.rb def hello puts "hello, world" end # in irb > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb') > iseq.path #=> /tmp/method.rb
Set
path for which this cookie applies
Returns the IP address for the connection.
If the session has not been started, returns the value set by ipaddr=
, or nil
if it has not been set:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
If the session has been started, returns the IP address from the socket:
http = Net::HTTP.new(hostname) http.start http.ipaddr # => "172.67.155.76" http.finish
Sets the IP address for the connection:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
The IP address may not be set if the session has been started.
Sends a PATCH request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Patch
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.patch('/todos/1', data) do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false,\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\"\n}"
With no block given, simply returns the response object:
http.patch('/todos/1', data) # => #<Net::HTTPCreated 201 Created readbody=true>
Sends a PROPPATCH request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Proppatch
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.proppatch('/todos/1', data)
Returns the IP address for the connection.
If the session has not been started, returns the value set by ipaddr=
, or nil
if it has not been set:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
If the session has been started, returns the IP address from the socket:
http = Net::HTTP.new(hostname) http.start http.ipaddr # => "172.67.155.76" http.finish
Sets the IP address for the connection:
http = Net::HTTP.new(hostname) http.ipaddr # => nil http.ipaddr = '172.67.155.76' http.ipaddr # => "172.67.155.76"
The IP address may not be set if the session has been started.
Sends a PATCH request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Patch
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.patch('/todos/1', data) do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false,\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\"\n}"
With no block given, simply returns the response object:
http.patch('/todos/1', data) # => #<Net::HTTPCreated 201 Created readbody=true>
Sends a PROPPATCH request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Proppatch
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.proppatch('/todos/1', data)
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"