Results for: "strip"

Same as IO.

Same as IO.

Returns true if stat is writable by the effective user id of this process.

File.stat("testfile").writable?   #=> true

Returns true if the operating system supports pipes and stat is a pipe; false otherwise.

Returns true if stat has its sticky bit set, false if it doesn’t or if the operating system doesn’t support this feature.

File.stat("testfile").sticky?   #=> false

Transfers ownership of the underlying memory to a new buffer, causing the current buffer to become uninitialized.

buffer = IO::Buffer.new('test')
other = buffer.transfer
other
# =>
# #<IO::Buffer 0x00007f136a15f7b0+4 SLICE>
# 0x00000000  74 65 73 74                                     test
buffer
# =>
# #<IO::Buffer 0x0000000000000000+0 NULL>
buffer.null?
# => true

If the buffer is private, meaning modifications to the buffer will not be replicated to the underlying file mapping.

# Create a test file:
File.write('test.txt', 'test')

# Create a private mapping from the given file. Note that the file here
# is opened in read-only mode, but it doesn't matter due to the private
# mapping:
buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::PRIVATE)
# => #<IO::Buffer 0x00007fce63f11000+4 MAPPED PRIVATE>

# Write to the buffer (invoking CoW of the underlying file buffer):
buffer.set_string('b', 0)
# => 1

# The file itself is not modified:
File.read('test.txt')
# => "test"

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.

No documentation available

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:

Creates a new Net::HTTP object, http, via Net::HTTP.new:

With no block given:

With a block given:

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 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.

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:

Sends a TRACE request to the server; returns an instance of a subclass of Net::HTTPResponse.

The request is based on the Net::HTTP::Trace object created from string path and initial headers hash initheader.

http = Net::HTTP.new(hostname)
http.trace('/todos/1')

Sends the given request req to the server; forms the response into a Net::HTTPResponse object.

The given req must be an instance of a subclass of Net::HTTPRequest. Argument body should be given only if needed for the request.

With no block given, returns the response object:

http = Net::HTTP.new(hostname)

req = Net::HTTP::Get.new('/todos/1')
http.request(req)
# => #<Net::HTTPOK 200 OK readbody=true>

req = Net::HTTP::Post.new('/todos')
http.request(req, 'xyzzy')
# => #<Net::HTTPCreated 201 Created readbody=true>

With a block given, calls the block with the response and returns the response:

req = Net::HTTP::Get.new('/todos/1')
http.request(req) do |res|
  p res
end # => #<Net::HTTPOK 200 OK readbody=true>

Output:

#<Net::HTTPOK 200 OK readbody=false>
No documentation available
No documentation available
No documentation available

Description

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"

Description

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"

This is used as a predicate, and ought to be called first.

Search took: 4ms  ·  Total Results: 2417