Proc&Lamda
Proc
Procs are full-fledged objects, so they have all the powers and abilities of objects. (Blocks do not.)
Unlike blocks, procs can be called over and over without rewriting them. This prevents you from having to retype the contents of your block every time you need to execute a particular bit of code.
&
is used to convert the cube proc into a block
.call
을 이용해서 proc을 쉽게 호출할 수 있다.
convert symbols to procs using that handy little
&
Lambda
proc과 lambda의 차이
argument 가 오류가 났을때 proc은 무시하고 nil처리 후 넘어가는데 lambda는 오류가난다.
lambda는 call이 되면 다시 마지막 코드로 돌아가는데 proc은 끝난다.
Scope
global variables : available everywhere
local variables : available certain methods
class variables : members of a certain class
instance variables : only available to particular instances of a class
Last updated