Register a Gem::Specification
for default gem.
Two formats for the specification are supported:
MRI 2.0 style, where spec.files contains unprefixed require names. The spec’s filenames will be registered as-is.
New style, where spec.files contains files prefixed with paths from spec.require_paths. The prefixes are stripped before registering the spec’s filenames. Unprefixed files are omitted.
Securely removes the entry given by path
, which should be the entry for a regular file, a symbolic link, or a directory.
Argument path
should be interpretable as a path.
Avoids a local vulnerability that can exist in certain circumstances; see Avoiding the TOCTTOU Vulnerability.
Optional argument force
specifies whether to ignore raised exceptions of StandardError
and its descendants.
Related: methods for deleting.
Securely removes the entry given by path
, which should be the entry for a regular file, a symbolic link, or a directory.
Argument path
should be interpretable as a path.
Avoids a local vulnerability that can exist in certain circumstances; see Avoiding the TOCTTOU Vulnerability.
Optional argument force
specifies whether to ignore raised exceptions of StandardError
and its descendants.
Related: methods for deleting.
Shortcut for defining multiple delegator methods, but with no provision for using a different name. The following two code samples have the same effect:
def_delegators :@records, :size, :<<, :map def_delegator :@records, :size def_delegator :@records, :<< def_delegator :@records, :map
Defines a method method which delegates to accessor (i.e. it calls the method of the same name in accessor). If new_name is provided, it is used as the name for the delegate method. Returns the name of the method defined.
Like Enumerable#slice_before
, but chains operation to be lazy-evaluated.
Performs a Miller-Rabin probabilistic primality test for bn
.
Deprecated in version 3.0. Use prime?
instead.
checks
and trial_div
parameters no longer have any effect.
Emit a scalar with value
and tag
Emit a sequence with list
and tag
Emit a sequence with map
and tag
Emit an arbitrary object obj
and tag
Called when the YAML
stream ends
Returns true if the stream is finished.
Returns true
if stat is readable by the real user id of this process.
File.stat("testfile").readable_real? #=> true
If stat is readable by others, returns an integer representing the file permission bits of stat. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
m = File.stat("/etc/passwd").world_readable? #=> 420 sprintf("%o", m) #=> "644"
Posts data to a host; returns a Net::HTTPResponse
object.
Argument url
must be a URI
; argument data
must be a hash:
_uri = uri.dup _uri.path = '/posts' data = {title: 'foo', body: 'bar', userId: 1} res = Net::HTTP.post_form(_uri, data) # => #<Net::HTTPCreated 201 Created readbody=true> puts res.body
Output:
{ "title": "foo", "body": "bar", "userId": "1", "id": 101 }
Sends a GET request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Get
object created from string path
and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.request_get('/todos') # => #<Net::HTTPOK 200 OK readbody=true>
With a block given, calls the block with the response object and returns the response object:
http.request_get('/todos') do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
#<Net::HTTPOK 200 OK readbody=false>
Sends a HEAD request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Head
object created from string path
and initial headers hash initheader
.
http = Net::HTTP.new(hostname) http.head('/todos/1') # => #<Net::HTTPOK 200 OK readbody=true>
Sends an HTTP request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTPRequest
object created from string path
, string data
, and initial headers hash header
. That object is an instance of the subclass of Net::HTTPRequest, that corresponds to the given uppercase string name
, which must be an HTTP request method or a WebDAV request method.
Examples:
http = Net::HTTP.new(hostname) http.send_request('GET', '/todos/1') # => #<Net::HTTPOK 200 OK readbody=true> http.send_request('POST', '/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
Posts data to a host; returns a Net::HTTPResponse
object.
Argument url
must be a URI
; argument data
must be a hash:
_uri = uri.dup _uri.path = '/posts' data = {title: 'foo', body: 'bar', userId: 1} res = Net::HTTP.post_form(_uri, data) # => #<Net::HTTPCreated 201 Created readbody=true> puts res.body
Output:
{ "title": "foo", "body": "bar", "userId": "1", "id": 101 }
Sends a GET request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Get
object created from string path
and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.request_get('/todos') # => #<Net::HTTPOK 200 OK readbody=true>
With a block given, calls the block with the response object and returns the response object:
http.request_get('/todos') do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
#<Net::HTTPOK 200 OK readbody=false>
Sends a HEAD request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Head
object created from string path
and initial headers hash initheader
.
http = Net::HTTP.new(hostname) http.head('/todos/1') # => #<Net::HTTPOK 200 OK readbody=true>