0
有没有一种优雅的方法来将整数数组分组到Ruby中的范围数组?红宝石组整数数组到范围数组
range1 = [*39..45]
#=> [39, 40, 41, 42, 43, 44, 45]
range2 = [*49..52]
#=> [49, 50, 51, 52]
range = range1 + range2
#=> [39, 40, 41, 42, 43, 44, 45, 49, 50, 51, 52]
range.build_ranges
#=> [39..45, 49..52]
另外这里:https://stackoverflow.com/questions/23840815/grouping-consecutive-numbers-in-an-array – tokland