Chinaunix

标题: 带序号循环Hash [打印本页]

作者: feiyang10086    时间: 2011-12-03 11:16
标题: 带序号循环Hash
带序号循环Hash









Ruby代码
  1. 1.hash.keys.each_with_index do |key, index|   
  2. 2.   value = hash[key]   
  3. 3.   print "key: #{key}, value: #{value}, index: #{index}\n"  
  4. 4.   # use key, value and index as desired   
  5. 5.end  
  6. hash.keys.each_with_index do |key, index|
  7.    value = hash[key]
  8.    print "key: #{key}, value: #{value}, index: #{index}\n"
  9.    # use key, value and index as desired
  10. end
复制代码
Ruby代码
  1. 1.hash.each_with_index do |(key, value), index|   
  2. 2.   print "key: #{key}, value: #{value}, index: #{index}\n"  
  3. 3.   # use key, value and index as desired   
  4. 4.end  
复制代码

作者: 冰释一片天    时间: 2011-12-21 22:15
谢谢分享  希望于楼主多多交流
作者: 2gua    时间: 2011-12-22 10:05
老发重复的帖子。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2