each

rng.each {| i | block } â rng
rng.each â an_enumerator
Instance Public methods

Iterates over the elements of range, passing each in turn to the block.

The each method can only be used if the begin object of the range supports the succ method. A TypeError is raised if the object does not have succ method defined (like Float).

If no block is given, an enumerator is returned instead.

(10..15).each {|n| print n, ' ' }
# prints: 10 11 12 13 14 15

(2.5..5).each {|n| print n, ' ' }
# raises: TypeError: can't iterate from Float
doc_ruby_on_rails
2015-05-01 01:26:51
Comments
Leave a Comment

Please login to continue.