如何在 Ruby 中做到这一点?
我在 ruby 中有一个数组(列表?):
allRows = ["start","one","two","start","three","four","start","five","six","seven","eight","start","nine","ten"]
我需要对此运行一个循环以获取一个列表,该列表将元素从“开始”直到遇到另一个“开始”,如下所示:
listOfRows = [["start","one","two"],["start","three","four"],["start","five","six","seven","eight"],["start","nine","ten"]]
I have an array(list?) in ruby:
allRows = ["start","one","two","start","three","four","start","five","six","seven","eight","start","nine","ten"]
I need to run a loop on this to get a list that clubs elements from "start" till another "start" is encountered, like the following:
listOfRows = [["start","one","two"],["start","three","four"],["start","five","six","seven","eight"],["start","nine","ten"]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于
Array#split
:Based on
Array#split
from Rails:如果您可以使用 ActiveSupport(例如,在 Rails 内部):
If you can use ActiveSupport (for example, inside Rails):