가능한 중복 기능을 전달하는 방법 :이 일을 알고
Shorter way to pass every element of an array to a function블록 대신
:
def inc(a)
a+1
end
[1,2,3].map{|a| inc a}
하지만 파이썬에서
, 난 그냥 필요를 쓰기 :map(inc, [1,2,3])
또는
[inc(x) for x in [1,2,3])
은 내가 루비에서 블록을 만드는 단계를 건너 뛸 수 있는지 궁금하고 이런 짓을했다 :
[1,2,3].map inc
# => ArgumentError: wrong number of arguments (0 for 1)
# from (irb):19:in `inc'
사람이 작업을 수행하는 방법에 대한 아이디어가 있습니까?
이 http://stackoverflow.com/questions/13834846/shorter-way-to-pass- 모든 요소를 배열로 변환하는 기능/13834860 # 13834860 – oldergod