我总是使用计数器来检查循环中的第一项(i==0):
i==0
i = 0 my_array.each do |item| if i==0 # do something with the first item end # common stuff i += 1 end
有没有一种更优雅的方法(也许是一种方法)呢?
https://stackoverflow.com/questions/8181390
相似问题