Tbpgr Blog

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

Ruby | Integer | downto

概要

Integer#downto

詳細

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

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

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

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