- 175 名前:デフォルトの名無しさん mailto:sage [2022/02/24(木) 12:04:16.87 ID:82W7j8jp.net]
- Ruby では、繰り返しにindex や、蓄積変数を付けたものがある。
または、each に付ける事もできる つまり、書き方が決まっている ary = [ "a", "b" ] ary.each_with_index do |element, index| p "#{ index }:#{ element }" end 出力 "0:a" "1:b" ary = [ "a", "b" ] # 初期値は1 ary.each.with_index( 1 ) do |element, index| p "#{ index }:#{ element }" end 出力 "1:a" "2:b" 同様に、蓄積変数を付けたものもある。 each_with_object( obj ), with_object( obj )
|

|