【发布时间】:2010-12-14 22:58:47
【问题描述】:
是否有任何内置的 Array 或 Enumerable 允许我使用块搜索元素并返回其索引?
类似于:
ar = [15,2,33,4,50,69]
indexes = ar.find_indexes {|item| item > 4 == 0}
# indexes will now contain 0,2,4,5
添加我自己的很容易,但我想知道这是否已经存在?
【问题讨论】:
标签: ruby arrays enumerable