带序号循环Hash_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > 带序号循环Hash

带序号循环Hash

 2011/12/5 7:34:43  夜鸣猪  http://hlee.iteye.com  我要评论(0)
  • 摘要:hash.keys.each_with_indexdo|key,index|value=hash[key]print"key:#{key},value:#{value},index:#{index}\n"#usekey,valueandindexasdesiredendhash.each_with_indexdo|(key,value),index|print"key:#{key},value:#{value},index:#{index}\n"#usekey
  • 标签:has Hash
hash.keys.each_with_index do |key, index|
   value = hash[key]
   print "key: #{key}, value: #{value}, index: #{index}\n"
   # use key, value and index as desired
end


hash.each_with_index do |(key, value), index|
   print "key: #{key}, value: #{value}, index: #{index}\n"
   # use key, value and index as desired
end
发表评论
用户名: 匿名