Extracts addr and ifindex from IPV6_PKTINFO ancillary data.
IPV6_PKTINFO is defined by RFC 3542.
addr = Addrinfo.ip("::1") ifindex = 0 ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) p ancdata.ipv6_pktinfo #=> [#<Addrinfo: ::1>, 0]
Write value to a registry value named name.
The value type is REG_SZ(write_s
), REG_DWORD(write_i
), or REG_BINARY(write_bin
).
Returns variable kind string.
tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name} #{variable.variable_kind}" end The result of above script is following: xlChart CONSTANT xlDialogSheet CONSTANT xlExcel4IntlMacroSheet CONSTANT xlExcel4MacroSheet CONSTANT xlWorksheet CONSTANT
Returns original filename recorded in the gzip file header, or nil
if original filename is not present.
Specify the original name (str
) in the gzip header.
Returns true
if stat is writable by the real user id of this process.
File.stat("testfile").writable_real? #=> true
If stat is writable 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("/tmp").world_writable? #=> 511 sprintf("%o", m) #=> "777"
Returns the number of the first source line where the instruction sequence was loaded from.
For example, using irb:
iseq = RubyVM::InstructionSequence.compile('num = 1 + 2') #=> <RubyVM::InstructionSequence:<compiled>@<compiled>> iseq.first_lineno #=> 1
Return trace points in the instruction sequence. Return an array of [line, event_symbol] pair.
Takes source
, which can be a string of Ruby code, or an open File
object. that contains Ruby source code. It parses and compiles using prism.
Optionally takes file
, path
, and line
which describe the file path, real path and first line number of the ruby code in source
which are metadata attached to the returned iseq
.
file
is used for ‘__FILE__` and exception backtrace. path
is used for require_relative
base. It is recommended these should be the same full path.
options
, which can be true
, false
or a Hash
, is used to modify the default behavior of the Ruby iseq compiler.
For details regarding valid compile options see ::compile_option=
.
RubyVM::InstructionSequence.compile("a = 1 + 2") #=> <RubyVM::InstructionSequence:<compiled>@<compiled>> path = "test.rb" RubyVM::InstructionSequence.compile(File.read(path), path, File.expand_path(path)) #=> <RubyVM::InstructionSequence:<compiled>@test.rb:1> file = File.open("test.rb") RubyVM::InstructionSequence.compile(file) #=> <RubyVM::InstructionSequence:<compiled>@<compiled>:1> path = File.expand_path("test.rb") RubyVM::InstructionSequence.compile(File.read(path), path, path) #=> <RubyVM::InstructionSequence:<compiled>@/absolute/path/to/test.rb:1>
Take a location from the prism parser and set the necessary instance variables.
Like Net::HTTP.get
, but writes the returned body to $stdout; returns nil
.
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 }
Sets the write timeout, in seconds, for self
to integer sec
; the initial value is 60.
Argument sec
must be a non-negative numeric value:
_uri = uri.dup _uri.path = '/posts' body = 'bar' * 200000 data = <<EOF {"title": "foo", "body": "#{body}", "userId": "1"} EOF headers = {'content-type': 'application/json'} http = Net::HTTP.new(hostname) http.write_timeout # => 60 http.post(_uri.path, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true> http.write_timeout = 0 http.post(_uri.path, data, headers) # Raises Net::WriteTimeout.
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>