feiyang10086 发表于 2011-12-03 11:16

带序号循环Hash

带序号循环Hash








Ruby代码1.hash.keys.each_with_index do |key, index|   
2.   value = hash   
3.   print "key: #{key}, value: #{value}, index: #{index}\n"
4.   # use key, value and index as desired   
5.end
hash.keys.each_with_index do |key, index|
   value = hash
   print "key: #{key}, value: #{value}, index: #{index}\n"
   # use key, value and index as desired
endRuby代码1.hash.each_with_index do |(key, value), index|   
2.   print "key: #{key}, value: #{value}, index: #{index}\n"
3.   # use key, value and index as desired   
4.end

冰释一片天 发表于 2011-12-21 22:15

谢谢分享希望于楼主多多交流

2gua 发表于 2011-12-22 10:05

老发重复的帖子。
页: [1]
查看完整版本: 带序号循环Hash