Possible Duplicate:
Sh或ter way to pass every element of an array to a function
我知道这会奏效:
def inc(a)
a+1
end
[1,2,3].map{|a| inc a}
但在Python中,我只需要写:
map(inc, [1,2,3])
或
[inc(x) f或 x in [1,2,3])
我想知道我是否可以跳过在Ruby中制作块的步骤,我做到了:
[1,2,3].map inc
# => ArgumentErr或: wrong number of arguments (0 f或 1)
# from (irb):19:in `inc'
有人知道怎么做吗?