prev - up - next - index

Enumerable

Enumerable is the Mix-in module for the enumeration. The including class must provide the method each. All methods provided by Enumerable are defined using each.

Methods:

collect {|item|...}

Returns an array of the result of the block evaluation over each item.

each_with_index {|item,index|...}

Iterates over each element with its index.

find {|item|...}
detect {|item|...}

Returns the first item which satisfies the block condition (i.e. the block's return value is true).

find_all {|item|...}
select {|item|...}

Returns an array of all items which satisfy the block condition.

grep(pattern)
grep(pattern) {|item|...}

Returns an array of all items which satisfy `pattern=== item'. If is called with the block, grep evaluates the block over every item matched.

member?(val)
include?(val)

Returns true if there is an item which equals to val. Comparison is done by the operator `=='.

index(val)

Returns the index of the item which equals to val using operator `=='. The index of the first item is 0. Returns nil if there is no matching item. It is meaningless for non-ordered enumerables.

length
size

Returns the number of items.

min

Returns the smallest item assuming all items are Comparable.

min{|a, b|...}

Returns the smallest item using the evaluated value of the block.

max

Returns the greatest item assuming all items are Comparable.

max{|a, b|...}

Returns the greatest item using the evaluated value of the block.

reject {|item|...}

Returns an array of all items which does not satisfy the block condition.

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

Returns the sorted array of the items. If the block is given, it must compare two items just like <=>.

to_a
entries

Converts an Enumerable to an array.


prev - up - next - index

matz@netlab.co.jp