Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Range#each

each {|element| ... } → self
each → an_enumerator

With a block given, passes each element of self to the block:

Example
a = []
(1..4).each {|element| a.push(element) } # => 1..4
a # => [1, 2, 3, 4]

Raises an exception unless self.first.respond_to?(:succ).

With no block given, returns an enumerator.

See also #cover? #end #count #entries also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0