Outline
目錄 (block、Proc、LAMBDA 篇)
- YIELD
- Proc
- LAMBDA
1. YIELD(丟 block 進去)
|
|
|
|
YIELD - ARGUMENTS
|
|
|
|
YIELD - RETURN VALUE
|
|
|
|
YIELD - 參數
|
|
|
|
include Enumerable
(路邊撿到拿來用)
|
|
|
|
2. Proc Proc.new {block}
.call
或&
|
|
|
|
3. LAMBDA lambda {block}
.call
|
|
multiple LAMBDAS(當作參數丟進去.call,而不用 yield)
|
|
|
|
&
LAMBDA 返回 BLOCK (當原本需要的還是一個 block)
原本
|
|
使用 lambda
|
|
互轉 Block -> proc -> block
|
|
&#.to_proc
as SYMBOL#TO_PROC 、 :
as pretzel colon
|
|
|
|