Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Integer | upto

概要

Integer#upto

詳細

ブロック指定した場合は、selfからuptoの引数へ値を増やしながら
ブロック内の処理を繰り返します。

ブロック指定しない場合は、Enumratorを返却します。

サンプルコード
# encoding: utf-8

1.upto(5) { |v| print "#{v}, " }
puts
puts 1.upto(5).class
出力
1, 2, 3, 4, 5, 
Enumerator