Results for: "to_proc"

Stop tracing object allocations.

Note that if ::trace_object_allocations_start is called n-times, then tracing will stop after calling ::trace_object_allocations_stop n-times.

No documentation available

Invoked by Process::Status.wait in order to wait for a specified process. See that method description for arguments description.

Suggested minimal implementation:

Thread.new do
  Process::Status.wait(pid, flags)
end.value

This hook is optional: if it is not present in the current scheduler, Process::Status.wait will behave as a blocking method.

Expected to return a Process::Status instance.

Sets the process title that appears on the ps(1) command. Not necessarily effective on all platforms. No exception will be raised regardless of the result, nor will NotImplementedError be raised even if the platform does not support the feature.

Calling this method does not affect the value of $0.

Process.setproctitle('myapp: worker #%d' % worker_id)

This method first appeared in Ruby 2.1 to serve as a global variable free means to change the process title.

Blocks can have a special set of parameters that automatically expand when given arrays if they have a single required parameter and no other parameters.

Example:

x += 1
  ^

Example:

x += 1
     ^

Example:

Foo::Bar += 1
   ^^^^^^^^

foo += bar

becomes

foo = foo + bar

Returns the number of online processors.

The result is intended as the number of processes to use all available processors.

This method is implemented using:

Example:

require 'etc'
p Etc.nprocessors #=> 4

The result might be smaller number than physical cpus especially when ruby process is bound to specific cpus. This is intended for getting better parallel processing.

Example: (Linux)

linux$ taskset 0x3 ./ruby -retc -e "p Etc.nprocessors"  #=> 2

foo += bar ^^^^^^^^^^

Example:

x.foo += 42
 ^^^     (for foo)
x.foo += 42
      ^  (for +)
x.foo += 42
 ^^^^^^^ (for foo=)

Example:

x.foo += 42
         ^^

Example:

x[1] += 42
 ^^^    (for [])
x[1] += 42
     ^  (for +)
x[1] += 42
 ^^^^^^ (for []=)

Example:

x[1] += 42
  ^^^^^^^^

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.

Sets the supplemental group access list; the new list includes:

Example:

Process.groups                # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
Process.initgroups('me', 30)  # => [30, 6, 10, 11]
Process.groups                # => [30, 6, 10, 11]

Not available on all platforms.

Returns an array of the group IDs in the supplemental group access list for the current process:

Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000]

These properties of the returned array are system-dependent:

Use this call to get a sorted and unique array:

Process.groups.uniq.sort

Sets the supplemental group access list to the given array of group IDs.

Process.groups                     # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27]
Process.groups = [27, 6, 10, 11]   # => [27, 6, 10, 11]
Process.groups                     # => [27, 6, 10, 11]

Returns the maximum number of group IDs allowed in the supplemental group access list:

Process.maxgroups # => 32

Sets the maximum number of group IDs allowed in the supplemental group access list.

Computes all combinations of elements from all the arrays, including both self and other_arrays:

With no block given, returns the combinations as an array of arrays:

p = [0, 1].product([2, 3])
# => [[0, 2], [0, 3], [1, 2], [1, 3]]
p.size # => 4
p = [0, 1].product([2, 3], [4, 5])
# => [[0, 2, 4], [0, 2, 5], [0, 3, 4], [0, 3, 5], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3,...
p.size # => 8

If self or any argument is empty, returns an empty array:

[].product([2, 3], [4, 5]) # => []
[0, 1].product([2, 3], []) # => []

If no argument is given, returns an array of 1-element arrays, each containing an element of self:

a.product # => [[0], [1], [2]]

With a block given, calls the block with each combination; returns self:

p = []
[0, 1].product([2, 3]) {|combination| p.push(combination) }
p # => [[0, 2], [0, 3], [1, 2], [1, 3]]

If self or any argument is empty, does not call the block:

[].product([2, 3], [4, 5]) {|combination| fail 'Cannot happen' }
# => []
[0, 1].product([2, 3], []) {|combination| fail 'Cannot happen' }
# => [0, 1]

If no argument is given, calls the block with each element of self as a 1-element array:

p = []
[0, 1].product {|combination| p.push(combination) }
p # => [[0], [1]]

Related: see Methods for Combining.

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"]

Generates a new enumerator object that generates a Cartesian product of given enumerable objects. This is equivalent to Enumerator::Product.new.

e = Enumerator.product(1..3, [4, 5])
e.to_a #=> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]
e.size #=> 6

When a block is given, calls the block with each N-element array generated and returns nil.

Search took: 3ms  ·  Total Results: 1548