在Ruby中指定foreach枚举器的起点 [英] Specify starting point of foreach enumerator in ruby
本文介绍了在Ruby中指定foreach枚举器的起点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个rake文件,该文件从外部CSV文件中提取数据并通过以下方法枚举:
I have a rake file that pulls in data from an external CSV file and enumerates through it with:
CSV.foreach(file, :headers => true) do |row|
在电子表格中指定起点的最有效方法是(红宝石)?
What is the most effective way (in ruby) to specify the starting point within the spreadsheet?
:headers => true允许我从第二行开始导入,但是如果我要从第20行开始怎么办?
:headers => true allows me to start importing from the second line, but what if I want to start a line 20?
推荐答案
使用.drop(#rows忽略):
Use .drop(#rows to ignore):
CSV.open(file,:headers => true).drop(20).each | row |
CSV.open(file, :headers => true).drop(20).each do |row|
这篇关于在Ruby中指定foreach枚举器的起点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文