Results for: "module_function"

Perform an operation in a block, raising an error if it takes longer than sec seconds to complete.

sec

Number of seconds to wait for the block to terminate. Any number may be used, including Floats to specify fractional seconds. A value of 0 or nil will execute the block without any timeout.

klass

Exception Class to raise if the block fails to terminate in sec seconds. Omitting will use the default, Timeout::Error

message

Error message to raise with Exception Class. Omitting will use the default, “execution expired”

Returns the result of the block if the block completed before sec seconds, otherwise throws an exception, based on the value of klass.

The exception thrown to terminate the given block cannot be rescued inside the block unless klass is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.

If a scheduler is defined, it will be used to handle the timeout by invoking Scheduler#timeout_after.

Note that this is both a method of module Timeout, so you can include Timeout into your classes so they have a timeout method, as well as a module method, so you can call it directly as Timeout.timeout().

Perform an operation in a block, raising an error if it takes longer than sec seconds to complete.

sec

Number of seconds to wait for the block to terminate. Any number may be used, including Floats to specify fractional seconds. A value of 0 or nil will execute the block without any timeout.

klass

Exception Class to raise if the block fails to terminate in sec seconds. Omitting will use the default, Timeout::Error

message

Error message to raise with Exception Class. Omitting will use the default, “execution expired”

Returns the result of the block if the block completed before sec seconds, otherwise throws an exception, based on the value of klass.

The exception thrown to terminate the given block cannot be rescued inside the block unless klass is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.

If a scheduler is defined, it will be used to handle the timeout by invoking Scheduler#timeout_after.

Note that this is both a method of module Timeout, so you can include Timeout into your classes so they have a timeout method, as well as a module method, so you can call it directly as Timeout.timeout().

Returns the scheduling priority for specified process, process group, or user.

Argument kind is one of:

Argument id is the ID for the process, process group, or user; zero specified the current ID for kind.

Examples:

Process.getpriority(Process::PRIO_USER, 0)    # => 19
Process.getpriority(Process::PRIO_PROCESS, 0) # => 19

Not available on all platforms.

See Process.getpriority.

Examples:

Process.setpriority(Process::PRIO_USER, 0, 19)    # => 0
Process.setpriority(Process::PRIO_PROCESS, 0, 19) # => 0
Process.getpriority(Process::PRIO_USER, 0)        # => 19
Process.getpriority(Process::PRIO_PROCESS, 0)     # => 19

Not available on all platforms.

Returns a Process::Tms structure that contains user and system CPU times for the current process, and for its children processes:

Process.times
# => #<struct Process::Tms utime=55.122118, stime=35.533068, cutime=0.0, cstime=0.002846>

The precision is platform-defined.

Returns the form how EC::Point data is encoded as ASN.1.

See also point_conversion_form=.

Sets the form how EC::Point data is encoded as ASN.1 as defined in X9.62.

format can be one of these:

:compressed

Encoded as z||x, where z is an octet indicating which solution of the equation y is. z will be 0x02 or 0x03.

:uncompressed

Encoded as z||x||y, where z is an octet 0x04.

:hybrid

Encodes as z||x||y, where z is an octet indicating which solution of the equation y is. z will be 0x06 or 0x07.

See the OpenSSL documentation for EC_GROUP_set_point_conversion_form()

Create a new RescueModifierNode node

No documentation available

returns match status of CSI/SS3 sequence and matched length

No documentation available
No documentation available
No documentation available

Return the best specification that contains the file matching path amongst the specs that are not activated.

Enumerates the outdated local gems yielding the local specification and the latest remote version.

This method may take some time to return as it must check each local gem against the server’s index.

No documentation available

Return the best specification in the record that contains the file matching path amongst the specs that are not activated.

Scanning is intentionally conservative because we have no way of rolling back an aggressive block (at this time)

If a block was stopped for some trivial reason, (like an empty line) but the next line would have caused it to be balanced then we can check that condition and grab just one more line either up or down.

For example, below if we’re scanning up, line 2 might cause the scanning to stop. This is because empty lines might denote logical breaks where the user intended to chunk code which is a good place to stop and check validity. Unfortunately it also means we might have a “dangling” keyword or end.

1 def bark
2
3 end

If lines 2 and 3 are in the block, then when this method is run it would see it is unbalanced, but that acquiring line 1 would make it balanced, so that’s what it does.

Returns a 2-element array [q, r], where

q = (self/other).floor    # Quotient
r = self % other          # Remainder

Examples:

11.divmod(4)              # => [2, 3]
11.divmod(-4)             # => [-3, -1]
-11.divmod(4)             # => [-3, 1]
-11.divmod(-4)            # => [2, -3]

12.divmod(4)              # => [3, 0]
12.divmod(-4)             # => [-3, 0]
-12.divmod(4)             # => [-3, 0]
-12.divmod(-4)            # => [3, 0]

13.divmod(4.0)            # => [3, 1.0]
13.divmod(Rational(4, 1)) # => [3, (1/1)]

Returns a 2-element array [q, r], where

q = (self/other).floor                  # Quotient
r = self % other                        # Remainder

Of the Core and Standard Library classes, only Rational uses this implementation.

Examples:

Rational(11, 1).divmod(4)               # => [2, (3/1)]
Rational(11, 1).divmod(-4)              # => [-3, (-1/1)]
Rational(-11, 1).divmod(4)              # => [-3, (1/1)]
Rational(-11, 1).divmod(-4)             # => [2, (-3/1)]

Rational(12, 1).divmod(4)               # => [3, (0/1)]
Rational(12, 1).divmod(-4)              # => [-3, (0/1)]
Rational(-12, 1).divmod(4)              # => [-3, (0/1)]
Rational(-12, 1).divmod(-4)             # => [3, (0/1)]

Rational(13, 1).divmod(4.0)             # => [3, 1.0]
Rational(13, 1).divmod(Rational(4, 11)) # => [35, (3/11)]

Returns a 2-element array [q, r], where

q = (self/other).floor      # Quotient
r = self % other            # Remainder

Examples:

11.0.divmod(4)              # => [2, 3.0]
11.0.divmod(-4)             # => [-3, -1.0]
-11.0.divmod(4)             # => [-3, 1.0]
-11.0.divmod(-4)            # => [2, -3.0]

12.0.divmod(4)              # => [3, 0.0]
12.0.divmod(-4)             # => [-3, 0.0]
-12.0.divmod(4)             # => [-3, -0.0]
-12.0.divmod(-4)            # => [3, -0.0]

13.0.divmod(4.0)            # => [3, 1.0]
13.0.divmod(Rational(4, 1)) # => [3, 1.0]

Changes permission bits on the named file(s) to the bit pattern represented by mode_int. Actual effects are operating system dependent (see the beginning of this section). On Unix systems, see chmod(2) for details. Returns the number of files processed.

File.chmod(0644, "testfile", "out")   #=> 2

Equivalent to File::chmod, but does not follow symbolic links (so it will change the permissions associated with the link, not the file referenced by the link). Often not available.

Changes permission bits on file to the bit pattern represented by mode_int. Actual effects are platform dependent; on Unix systems, see chmod(2) for details. Follows symbolic links. Also see File#lchmod.

f = File.new("out", "w");
f.chmod(0644)   #=> 0

Creates an infinite enumerator from any block, just called over and over. The result of the previous iteration is passed to the next one. If initial is provided, it is passed to the first iteration, and becomes the first element of the enumerator; if it is not provided, the first iteration receives nil, and its result becomes the first element of the iterator.

Raising StopIteration from the block stops an iteration.

Enumerator.produce(1, &:succ)   # => enumerator of 1, 2, 3, 4, ....

Enumerator.produce { rand(10) } # => infinite random number sequence

ancestors = Enumerator.produce(node) { |prev| node = prev.parent or raise StopIteration }
enclosing_section = ancestors.find { |n| n.type == :section }

Using ::produce together with Enumerable methods like Enumerable#detect, Enumerable#slice_after, Enumerable#take_while can provide Enumerator-based alternatives for while and until cycles:

# Find next Tuesday
require "date"
Enumerator.produce(Date.today, &:succ).detect(&:tuesday?)

# Simple lexer:
require "strscan"
scanner = StringScanner.new("7+38/6")
PATTERN = %r{\d+|[-/+*]}
Enumerator.produce { scanner.scan(PATTERN) }.slice_after { scanner.eos? }.first
# => ["7", "+", "38", "/", "6"]
Search took: 20ms  ·  Total Results: 5313