Skip to content

Instantly share code, notes, and snippets.

@k2works
Created December 22, 2014 07:30
Show Gist options
  • Save k2works/d7fbdac02164f2ef6295 to your computer and use it in GitHub Desktop.
Save k2works/d7fbdac02164f2ef6295 to your computer and use it in GitHub Desktop.
クロージャとしてのProcオブジェクトの動作
# 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