Enumerable

A mix-in for repeating classes. This module's methods are all defined via each, so each must be defined in any class which includes this module.

Method

all?
all? {|item| ... }

Returns TRUE when all items are true. If any item is false, immediately returns FALSE.

When using a block, evaluates the block against each item and returns TRUE if all outcomes are true. If the block returns FALSE at any time, immediately returns FALSE.

p [1,2,3].all? {|v| v > 0}   # => true
p [1,2,3].all? {|v| v > 1}   # => false
any?
any? {|item| ... }

Returns FALSE when all items are false. If any item is true, immediately returns TRUE.

When using a block, evaluates the block against each item and returns FALSE if all outcomes are false. If the block returns TRUE at any time, immediately returns TRUE.

p [1,2,3].any? {|v| v > 3}   # => false
p [1,2,3].any? {|v| v > 1}   # => true
find {|item| ... }

Returns the first item that tested as true during the block evaluation. If no item was true, returns nil.

find_all {|item| ... }

Returns an array of all items that tested as true during the block evaluation. If no item was true, returns an empty array.

include?(val)

Returns TRUE when the list includes an item that satisfies the relationship val ==.

max

Returns the largest item. Assumes all items are comparable via the <=> method.

max {|a, b| ... }

Compares each item based on the block's evaluated value and returns the largest item.

Anticipates a block value that will be a positive integer when a>b, 0 when a==b, and a negative integer when a<b. When the block returns a non-integer, throws a TypeError exception.

min

Returns the smallest item. Assumes all items are comparable via the <=> method.

min {|a, b| ... }

Compares each item based on the block's evaluated value and returns the smallest item.

Anticipates a block value that will be a positive integer when a>b, 0 when a==b, and a negative integer when a<b. When the block returns a non-integer, throws a TypeError exception.

sort
sort {|a, b| ... }

Creates and returns an array of all items sorted in ascending order.

When not using a block, calls the <=> against each item and sorts based upon those results.

To sort using other methods besides <=>, select a block; the items will be sorted based on the evaluation of this block. Anticipates a block value that will be a positive integer when a>b, 0 when a==b, and a negative integer when a<b. When the block returns a non-integer, throws a TypeError exception.

to_a
entries

Returns an array of all items.

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)