Skip to content

Instantly share code, notes, and snippets.

@stevencch99
Last active May 11, 2019 13:19
Show Gist options
  • Save stevencch99/e708db5d9137eba3ce146c1a610f2493 to your computer and use it in GitHub Desktop.
Save stevencch99/e708db5d9137eba3ce146c1a610f2493 to your computer and use it in GitHub Desktop.
# 創造 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