Last active
May 11, 2019 13:19
-
-
Save stevencch99/e708db5d9137eba3ce146c1a610f2493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 創造 Proc 物件並指派給變數 double | |
double = Proc.new { |number| number * 2 } | |
# shorthand | |
double = proc { |number| number * 2 } | |
# 作為參數傳入另一個方法 | |
def make_proc(&block) | |
block | |
end | |
# 或者透過 Proc.new 去承接傳入的 block | |
def make_proc | |
Proc.new | |
end | |
double = make_proc { |number| number * 2 } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment