하위링크들

루비 Lambdas와 Procs 차이점 번역

Quill 2015. 5. 3. 17:32
Lambdas vs. Procs

If you're thinking that procs and lambdas look super similar, that's because they are! There are only two main differences.

Proc과 lambdas가 완전 비슷해보이시나요? 진짜 이놈들은 서로 비슷해요! 크게 두개의 차이점 밖에 없답니다.

First, a lambda checks the number of arguments passed to it, while a proc does not. 

첫째로, 람다는 인자의 갯수를 체크하는데 proc은 그런 짓을 안해요.

This means that a lambda will throw an error if you pass it the wrong number of arguments, whereas a proc will ignore unexpected arguments and assign nil to any that are missing.

이건 람다가 잘못된 인자 갯수를 주면 에러가 난다는 걸 뜻해요. 그러나 proc은 예상 밖의 인자들을 무시하고  없는 인자는 nil로 치환해버리지요.

Second, when a lambda returns, it passes control back to the calling method; when a proc returns, it does so immediately, without going back to the calling method.

둘째로, 람다의 결과가 반환될 때 콜링 메소드를 사용해야하지만 proc은 그냥 그런거 없이 바로 결과를 가져다 줘요.

To see how this works, take a look at the code in the editor. Our first method calls a proc; the second calls a lambda.

자 어떻게 되는 지 코드 에디터를 통해 한번 직접 보시지요. 우리의 첫번재 함수는 proc를 부른다음에 람다를 부릅니다. 




반응형