Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
d = [2,4,6] d.collect{ |i| i * 2 } #=> [4,8,12]
我尝试对多维数组做同样的事情
d = [[1,3],[2,4]] d.collect { |i,j| i*2, j*2 } #=> getting syntax error
要表示数组,您需要用[and包围它们]:
[
]
d.collect { |i,j| [i*2, j*2] } # ^ ^ # => [[2, 6], [4, 8]]