Returns a 3-element array of substrings of self
.
Matches a pattern against self
, scanning backwards from the end. The pattern is:
string_or_regexp
itself, if it is a Regexp
.
Regexp.quote(string_or_regexp)
, if string_or_regexp
is a string.
If the pattern is matched, returns pre-match, last-match, post-match:
'hello'.rpartition('l') # => ["hel", "l", "o"] 'hello'.rpartition('ll') # => ["he", "ll", "o"] 'hello'.rpartition('h') # => ["", "h", "ello"] 'hello'.rpartition('o') # => ["hell", "o", ""] 'hello'.rpartition(/l+/) # => ["hel", "l", "o"] 'hello'.rpartition('') # => ["hello", "", ""] 'тест'.rpartition('т') # => ["тес", "т", ""] 'こんにちは'.rpartition('に') # => ["こん", "に", "ちは"]
If the pattern is not matched, returns two empty strings and a copy of self
:
'hello'.rpartition('x') # => ["", "", "hello"]
Related: String#partition
, String#split
.
Returns a copy of self
that has ASCII-8BIT encoding; the underlying bytes are not modified:
s = "\x99" s.encoding # => #<Encoding:UTF-8> t = s.b # => "\x99" t.encoding # => #<Encoding:ASCII-8BIT> s = "\u4095" # => "䂕" s.encoding # => #<Encoding:UTF-8> s.bytes # => [228, 130, 149] t = s.b # => "\xE4\x82\x95" t.encoding # => #<Encoding:ASCII-8BIT> t.bytes # => [228, 130, 149]
Returns a frozen, possibly pre-existing copy of the string.
The returned String will be deduplicated as long as it does not have any instance variables set on it and is not a String
subclass.
String#dedup
is an alias for String#-@
.
Like encode
, but applies encoding changes to self
; returns self
.
Get the address as an Integer
for the function named name
. The function is searched via dlsym on RTLD_NEXT.
See man(3) dlsym() for more info.
Get the address as an Integer
for the function named name
.
Fetch struct member name
if only one argument is specified. If two arguments are specified, the first is an offset and the second is a length and this method returns the string of length
bytes beginning at offset
.
Examples:
my_struct = struct(['int id']).malloc my_struct.id = 1 my_struct['id'] # => 1 my_struct[0, 4] # => "\x01\x00\x00\x00".b
Get the underlying pointer for ruby object val
and return it as a Fiddle::Pointer
object.
Returns integer stored at index.
If start and length are given, a string containing the bytes from start of length will be returned.
Gets all key-value pairs in a specific section from the current configuration.
Given the following configurating file being loaded:
config = OpenSSL::Config.load('foo.cnf') #=> #<OpenSSL::Config sections=["default"]> puts config.to_s #=> [ default ] # foo=bar
You can get a hash of the specific section like so:
config['default'] #=> {"foo"=>"bar"}
Read a registry value named name and return its value data. The class of the value is the same as the read
method returns.
If the value type is REG_EXPAND_SZ, returns value data whose environment variables are replaced. If the value type is neither REG_SZ, REG_MULTI_SZ, REG_DWORD, REG_DWORD_BIG_ENDIAN, nor REG_QWORD, TypeError
is raised.
The meaning of rtype is the same as for the read
method.
Returns the element of WIN32OLE_VARIANT object(OLE array). This method is available only when the variant type of WIN32OLE_VARIANT object is VT_ARRAY.
REMARK:
The all indices should be 0 or natural number and lower than or equal to max indices. (This point is different with Ruby Array indices.) obj = WIN32OLE_VARIANT.new([[1,2,3],[4,5,6]]) p obj[0,0] # => 1 p obj[1,0] # => 4 p obj[2,0] # => WIN32OLERuntimeError p obj[0, -1] # => WIN32OLERuntimeError
Retrieves a weakly referenced object with the given key
Retrieve the session data for key key
.
Returns data from the table; does not modify the table.
Form: table[n]
, n
an integer.
Access mode: :row
or :col_or_row
.
Return value: nth row of the table, if that row exists; otherwise nil
.
Returns the nth row of the table if that row exists:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_row! # => #<CSV::Table mode:row row_count:4> table[1] # => #<CSV::Row "Name":"bar" "Value":"1"> table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4> table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
Counts backward from the last row if n
is negative:
table[-1] # => #<CSV::Row "Name":"baz" "Value":"2">
Returns nil
if n
is too large or too small:
table[4] # => nil table[-4] # => nil
Raises an exception if the access mode is :row
and n
is not an Integer:
table.by_row! # => #<CSV::Table mode:row row_count:4> # Raises TypeError (no implicit conversion of String into Integer): table['Name']
Form: table[n]
, n
an Integer.
Access mode: :col
.
Return value: nth column of the table, if that column exists; otherwise an Array of nil
fields of length self.size
.
Returns the nth column of the table if that column exists:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_col! # => #<CSV::Table mode:col row_count:4> table[1] # => ["0", "1", "2"]
Counts backward from the last column if n
is negative:
table[-2] # => ["foo", "bar", "baz"]
Returns an Array of nil
fields if n
is too large or too small:
table[4] # => [nil, nil, nil] table[-4] # => [nil, nil, nil]
Form: table[range]
, range
a Range object.
Access mode: :row
or :col_or_row
.
Return value: rows from the table, beginning at row range.start
, if those rows exists.
Returns rows from the table, beginning at row range.first
, if those rows exist:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_row! # => #<CSV::Table mode:row row_count:4> rows = table[1..2] # => #<CSV::Row "Name":"bar" "Value":"1"> rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">] table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4> rows = table[1..2] # => #<CSV::Row "Name":"bar" "Value":"1"> rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
If there are too few rows, returns all from range.start
to the end:
rows = table[1..50] # => #<CSV::Row "Name":"bar" "Value":"1"> rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
Special case: if range.start == table.size
, returns an empty Array:
table[table.size..50] # => []
If range.end
is negative, calculates the ending index from the end:
rows = table[0..-1] rows # => [#<CSV::Row "Name":"foo" "Value":"0">, #<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
If range.start
is negative, calculates the starting index from the end:
rows = table[-1..2] rows # => [#<CSV::Row "Name":"baz" "Value":"2">]
If range.start
is larger than table.size
, returns nil
:
table[4..4] # => nil
Form: table[range]
, range
a Range object.
Access mode: :col
.
Return value: column data from the table, beginning at column range.start
, if those columns exist.
Returns column values from the table, if the column exists; the values are arranged by row:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_col! table[0..1] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
Special case: if range.start == headers.size
, returns an Array (size: table.size
) of empty Arrays:
table[table.headers.size..50] # => [[], [], []]
If range.end
is negative, calculates the ending index from the end:
table[0..-1] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
If range.start
is negative, calculates the starting index from the end:
table[-2..2] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
If range.start
is larger than table.size
, returns an Array of nil
values:
table[4..4] # => [nil, nil, nil]
Form: table[header]
, header
a String header.
Access mode: :col
or :col_or_row
Return value: column data from the table, if that header
exists.
Returns column values from the table, if the column exists:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_col! # => #<CSV::Table mode:col row_count:4> table['Name'] # => ["foo", "bar", "baz"] table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4> col = table['Name'] col # => ["foo", "bar", "baz"]
Modifying the returned column values does not modify the table:
col[0] = 'bat' col # => ["bat", "bar", "baz"] table['Name'] # => ["foo", "bar", "baz"]
Returns an Array of nil
values if there is no such column:
table['Nosuch'] # => [nil, nil, nil]
Retrieves key
from the GW