Returns the Encoding
object that represents the encoding of the file. If io is in write mode and no encoding is specified, returns nil
.
Returns the Encoding
of the internal string if conversion is specified. Otherwise returns nil
.
If single argument is specified, read string from io is tagged with the encoding specified. If encoding is a colon separated two encoding names “A:B”, the read string is converted from encoding A (external encoding) to encoding B (internal encoding), then tagged with B. If two arguments are specified, those must be encoding objects or encoding names, and the first one is the external encoding, and the second one is the internal encoding. If the external encoding and the internal encoding is specified, optional hash argument specify the conversion option.
Returns false if rxp is applicable to a string with any ASCII compatible encoding. Returns true otherwise.
r = /a/ r.fixed_encoding? #=> false r =~ "\u{6666} a" #=> 2 r =~ "\xa1\xa2 a".force_encoding("euc-jp") #=> 2 r =~ "abc".force_encoding("euc-jp") #=> 0 r = /a/u r.fixed_encoding? #=> true r.encoding #=> #<Encoding:UTF-8> r =~ "\u{6666} a" #=> 2 r =~ "\xa1\xa2".force_encoding("euc-jp") #=> Encoding::CompatibilityError r =~ "abc".force_encoding("euc-jp") #=> 0 r = /\u{6666}/ r.fixed_encoding? #=> true r.encoding #=> #<Encoding:UTF-8> r =~ "\u{6666} a" #=> 0 r =~ "\xa1\xa2".force_encoding("euc-jp") #=> Encoding::CompatibilityError r =~ "abc".force_encoding("euc-jp") #=> nil
Returns true if this class can be used to create an instance from a serialised JSON
string. The class has to implement a class method json_create that expects a hash as first parameter. The hash should include the required data.
Returns true for IPv4 multicast address (224.0.0.0/4). It returns false otherwise.
Returns true for IPv6 multicast address (ff00::/8). It returns false otherwise.
Returns the Encoding
object that represents the encoding of the file. If strio is write mode and no encoding is specified, returns nil
.
Returns the Encoding
of the internal string if conversion is specified. Otherwise returns nil.
Specify the encoding of the StringIO
as ext_enc. Use the default external encoding if ext_enc is nil. 2nd argument int_enc and optional hash opt argument are ignored; they are for API compatibility to IO
.
Tests whether the given pattern
is matched from the current scan pointer. Advances the scan pointer if advance_pointer_p
is true. Returns the matched string if return_string_p
is true. The match register is affected.
“full” means “#scan with full parameters”.
Scans the string until the pattern
is matched. Advances the scan pointer if advance_pointer_p
, otherwise not. Returns the matched string if return_string_p
is true, otherwise returns the number of bytes advanced. This method does affect the match register.
Returns the external encoding for files read from ARGF
as an Encoding
object. The external encoding is the encoding of the text as stored in a file. Contrast with ARGF.internal_encoding
, which is the encoding used to represent this text within Ruby.
To set the external encoding use ARGF.set_encoding
.
For example:
ARGF.external_encoding #=> #<Encoding:UTF-8>
Returns the internal encoding for strings read from ARGF
as an Encoding
object.
If ARGF.set_encoding
has been called with two encoding names, the second is returned. Otherwise, if Encoding.default_external
has been set, that value is returned. Failing that, if a default external encoding was specified on the command-line, that value is used. If the encoding is unknown, nil
is returned.
If single argument is specified, strings read from ARGF
are tagged with the encoding specified.
If two encoding names separated by a colon are given, e.g. “ascii:utf-8”, the read string is converted from the first encoding (external encoding) to the second encoding (internal encoding), then tagged with the second encoding.
If two arguments are specified, they must be encoding objects or encoding names. Again, the first specifies the external encoding; the second specifies the internal encoding.
If the external encoding and the internal encoding are specified, the optional Hash
argument can be used to adjust the conversion process. The structure of this hash is explained in the String#encode
documentation.
For example:
ARGF.set_encoding('ascii') # Tag the input as US-ASCII text ARGF.set_encoding(Encoding::UTF_8) # Tag the input as UTF-8 text ARGF.set_encoding('utf-8','ascii') # Transcode the input from US-ASCII # to UTF-8.
Builds a regular expression in @encoding
. All chunks
will be transcoded to that encoding.
Builds a String in @encoding
. All chunks
will be transcoded to that encoding.
Returns the encoding of the internal IO
object or the default
if the encoding cannot be determined.
Returns the methods available to this delegate object as the union of this object’s and _getobj_ protected methods.
Dup internal hash.
Creates an enumerator for each chunked elements. The beginnings of chunks are defined by the block.
This method split each chunk using adjacent elements, elt_before and elt_after, in the receiver enumerator. This method split chunks between elt_before and elt_after where the block returns false
.
The block is called the length of the receiver enumerator minus one.
The result enumerator yields the chunked elements as an array. So each
method can be called as follows:
enum.chunk_while { |elt_before, elt_after| bool }.each { |ary| ... }
Other methods of the Enumerator
class and Enumerable
module, such as to_a
, map
, etc., are also usable.
For example, one-by-one increasing subsequence can be chunked as follows:
a = [1,2,4,9,10,11,12,15,16,19,20,21] b = a.chunk_while {|i, j| i+1 == j } p b.to_a #=> [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]] c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last}" } p c #=> [[1, 2], [4], "9-12", [15, 16], "19-21"] d = c.join(",") p d #=> "1,2,4,9-12,15,16,19-21"
Increasing (non-decreasing) subsequence can be chunked as follows:
a = [0, 9, 2, 2, 3, 2, 7, 5, 9, 5] p a.chunk_while {|i, j| i <= j }.to_a #=> [[0, 9], [2, 2, 3], [2, 7], [5, 9], [5]]
Adjacent evens and odds can be chunked as follows: (Enumerable#chunk
is another way to do it.)
a = [7, 5, 9, 2, 0, 7, 9, 4, 2, 0] p a.chunk_while {|i, j| i.even? == j.even? }.to_a #=> [[7, 5, 9], [2, 0], [7, 9], [4, 2, 0]]
Enumerable#slice_when
does the same, except splitting when the block returns true
instead of false
.
Counts nodes for each node type.
This method is only for MRI developers interested in performance and memory usage of Ruby programs.
It returns a hash as:
{:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.
Note: The contents of the returned hash is implementation defined. It may be changed in future.
This method is only expected to work with C Ruby.
Initiates garbage collection, unless manually disabled.
This method is defined with keyword arguments that default to true:
def GC.start(full_mark: true, immediate_sweep: true); end
Use full_mark: false to perform a minor GC
. Use immediate_sweep: false to defer sweeping (use lazy sweep).
Note: These keyword arguments are implementation and version dependent. They are not guaranteed to be future-compatible, and may be ignored if the underlying implementation does not support them.
Initiates garbage collection, unless manually disabled.
This method is defined with keyword arguments that default to true:
def GC.start(full_mark: true, immediate_sweep: true); end
Use full_mark: false to perform a minor GC
. Use immediate_sweep: false to defer sweeping (use lazy sweep).
Note: These keyword arguments are implementation and version dependent. They are not guaranteed to be future-compatible, and may be ignored if the underlying implementation does not support them.