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.
Returns the encoding of the internal IO
object.
Returns the submatrix obtained by deleting the specified row and column.
Matrix.diagonal(9, 5, -3, 4).first_minor(1, 2) # => 9 0 0 # 0 0 0 # 0 0 4
Returns additional info.
Returns the factorization of value
.
For an arbitrary integer:
p_1**e_1 * p_2**e_2 * ... * p_n**e_n,
prime_division
returns an array of pairs of integers:
[[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]].
Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).
value
An arbitrary integer.
generator
Optional. A pseudo-prime generator. generator
.succ must return the next pseudo-prime number in ascending order. It must generate all prime numbers, but may also generate non-prime numbers, too.
ZeroDivisionError
when value
is zero.
Prime.prime_division(45) #=> [[3, 2], [5, 1]] 3**2 * 5 #=> 45
Returns whether or not the asynchronous queue is empty.
Since Thread::handle_interrupt
can be used to defer asynchronous events, this method can be used to determine if there are any deferred events.
If you find this method returns true, then you may finish :never
blocks.
For example, the following method processes deferred asynchronous events immediately.
def Thread.kick_interrupt_immediately Thread.handle_interrupt(Object => :immediate) { Thread.pass } end
If error
is given, then check only for error
type deferred events.
th = Thread.new{ Thread.handle_interrupt(RuntimeError => :on_blocking){ while true ... # reach safe point to invoke interrupt if Thread.pending_interrupt? Thread.handle_interrupt(Object => :immediate){} end ... end } } ... th.raise # stop thread
This example can also be written as the following, which you should use to avoid asynchronous interrupts.
flag = true th = Thread.new{ Thread.handle_interrupt(RuntimeError => :on_blocking){ while true ... # reach safe point to invoke interrupt break if flag == false ... end } } ... flag = false # stop thread
Returns whether or not the asynchronous queue is empty for the target thread.
If error
is given, then check only for error
type deferred events.
See ::pending_interrupt?
for more information.
Ruby tries to load the library named string relative to the requiring file’s path. If the file’s path cannot be determined a LoadError
is raised. If a file is loaded true
is returned and false otherwise.
Is this tar entry a directory?
Checks the validity of thisUpdate and nextUpdate fields of this SingleResponse
. This checks the current time is within the range thisUpdate to nextUpdate.
It is possible that the OCSP
request takes a few seconds or the time is not accurate. To avoid rejecting a valid response, this method allows the times to be within nsec seconds of the current time.
Some responders don’t set the nextUpdate field. This may cause a very old response to be considered valid. The maxsec parameter can be used to limit the age of responses.
Re-composes a prime factorization and returns the product.
See Prime#int_from_prime_division
for more details.
Execute the provided block, but preserve the rounding mode
BigDecimal.save_rounding_mode do BigDecimal.mode(BigDecimal::ROUND_MODE, :up) puts BigDecimal.mode(BigDecimal::ROUND_MODE) end
For use with the BigDecimal::ROUND_*
See BigDecimal.mode
Specifies VI editing mode. See the manual of GNU Readline
for details of VI editing mode.
Raises NotImplementedError
if the using readline library does not support.