「Ruby」for文で配列の多数要素を取得する方法
書式
for 変数名1,変数名2 in 配列名
使用例
#!/usr/bin/ruby # -*- coding: UTF-8 -*- cftArr = {:keyA => "AA01",:keyB => "BB02",:keyC => "CC03",:keyD => "DD04"} for key,value in cftArr puts "key is " + "#{key}" puts "value is " + "#{value}" end
実行結果
>ruby test.rb
key is keyA
value is AA01
key is keyB
value is BB02
key is keyC
value is CC03
key is keyD
value is DD04