Created
December 22, 2014 07:30
-
-
Save k2works/d7fbdac02164f2ef6295 to your computer and use it in GitHub Desktop.
クロージャとしてのProcオブジェクトの動作
This file contains 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
# coding: utf-8 | |
def create_proc | |
str = 'from create_proc' | |
Proc.new { str } | |
end | |
proc_obj = create_proc | |
str = 'from toplevel' | |
# proc_obj内で呼び出されるstrの参照はcreate_proc内のstrになっている | |
proc_obj.call # => "from create_proc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment