Returns compression level.
Returns true
if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
Returns true
if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
Returns true
if stat is executable or if the operating system doesn’t distinguish executable files from nonexecutable files. The tests are made using the effective owner of the process.
File.stat("testfile").executable? #=> false
Returns true
if stat is a regular file (not a device file, pipe, socket, etc.).
File.stat("testfile").file? #=> true
Returns a human-readable string representation of the buffer. The exact format is subject to change.
buffer = IO::Buffer.for("Hello World") puts buffer.hexdump # 0x00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello World
As buffers are usually fairly big, you may want to limit the output by specifying the offset and length:
puts buffer.hexdump(6, 5) # 0x00000006 57 6f 72 6c 64 World
If the buffer was freed with free
, transferred with transfer
, or was never allocated in the first place.
buffer = IO::Buffer.new(0) buffer.null? #=> true buffer = IO::Buffer.new(4) buffer.null? #=> false buffer.free buffer.null? #=> true
Fill buffer with value
, starting with offset
and going for length
bytes.
buffer = IO::Buffer.for('test') # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 74 65 73 74 test buffer.clear # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 00 00 00 00 .... buf.clear(1) # fill with 1 # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 01 01 01 01 .... buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 01 02 02 01 .... buffer.clear(2, 1) # fill with 2, starting from offset 1 # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 01 02 02 02 ....
Returns the instruction sequence as a String
in human readable form.
puts RubyVM::InstructionSequence.compile('1 + 2').disasm
Produces:
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== 0000 trace 1 ( 1) 0002 putobject 1 0004 putobject 2 0006 opt_plus <ic:1> 0008 leave
Takes source
, which can be a string of Ruby code, or an open File
object. that contains Ruby source code.
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>
Takes body
, a Method
or Proc
object, and returns a String
with the human readable instructions for body
.
For a Method
object:
# /tmp/method.rb def hello puts "hello, world" end puts RubyVM::InstructionSequence.disasm(method(:hello))
Produces:
== disasm: <RubyVM::InstructionSequence:hello@/tmp/method.rb>============ 0000 trace 8 ( 1) 0002 trace 1 ( 2) 0004 putself 0005 putstring "hello, world" 0007 send :puts, 1, nil, 8, <ic:0> 0013 trace 16 ( 3) 0015 leave ( 2)
For a Proc:
# /tmp/proc.rb p = proc { num = 1 + 2 } puts RubyVM::InstructionSequence.disasm(p)
Produces:
== disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>=== == catch table | catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000 | catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012 |------------------------------------------------------------------------ local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1) [ 2] num 0000 trace 1 ( 1) 0002 putobject 1 0004 putobject 2 0006 opt_plus <ic:1> 0008 dup 0009 setlocal num, 0 0012 leave
Delete the session from storage. Also closes the storage.
Note that the session’s data is not automatically deleted upon the session expiring.
Removes a specified field from self
; returns the 2-element Array [header, value]
if the field exists.
If an Integer argument index
is given, removes and returns the field at offset index
, or returns nil
if the field does not exist:
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.delete(1) # => ["Name", "Bar"] row.delete(50) # => nil
Otherwise, if the single argument header
is given, removes and returns the first-found field with the given header, of returns a new empty Array if the field does not exist:
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.delete('Name') # => ["Name", "Foo"] row.delete('NAME') # => []
If argument header
and Integer argument offset
are given, removes and returns the first-found field with the given header whose index
is at least as large as offset
:
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.delete('Name', 1) # => ["Name", "Bar"] row.delete('NAME', 1) # => []
If the access mode is :row
or :col_or_row
, and each argument is either an Integer or a Range, returns deleted rows. Otherwise, returns deleted columns data.
In either case, the returned values are in the order specified by the arguments. Arguments may be repeated.
Returns rows as an Array of CSV::Row objects.
One index:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) deleted_values = table.delete(0) deleted_values # => [#<CSV::Row "Name":"foo" "Value":"0">]
Two indexes:
table = CSV.parse(source, headers: true) deleted_values = table.delete(2, 0) deleted_values # => [#<CSV::Row "Name":"baz" "Value":"2">, #<CSV::Row "Name":"foo" "Value":"0">]
Returns columns data as column Arrays.
One header:
table = CSV.parse(source, headers: true) deleted_values = table.delete('Name') deleted_values # => ["foo", "bar", "baz"]
Two headers:
table = CSV.parse(source, headers: true) deleted_values = table.delete('Value', 'Name') deleted_values # => [["0", "1", "2"], ["foo", "bar", "baz"]]
Sends a DELETE request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Delete
object created from string path
and initial headers hash initheader
.
http = Net::HTTP.new(hostname) http.delete('/todos/1')
Sends a MOVE request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Move
object created from string path
and initial headers hash initheader
.
http = Net::HTTP.new(hostname) http.move('/todos/1')
Sets the body for the request:
req = Net::HTTP::Post.new(uri) req.body # => nil req.body = '{"title": "foo","body": "bar","userId": 1}' req.body # => "{\"title\": \"foo\",\"body\": \"bar\",\"userId\": 1}"
Returns the string response body; note that repeated calls for the unmodified body return a cached string:
path = '/todos/1' Net::HTTP.start(hostname) do |http| res = http.get(path) p res.body p http.head(path).body # No body. end
Output:
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}" nil
Sets the body of the response to the given value.
v
Public setter for the typecode v
(with validation).
See also URI::FTP.check_typecode
.
require 'uri' uri = URI.parse("ftp://john@ftp.example.com/my_file.img") #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img> uri.typecode = "i" uri #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
Searches list id
for opt
and the optional patterns for completion pat
. If icase
is true, the search is case insensitive. The result is returned or yielded if a block is given. If it isn’t found, nil is returned.
Appends sep
to the text to be output. By default sep
is ‘ ’
width
argument is here for compatibility. It is a noop argument.