Created
December 18, 2016 10:48
-
-
Save pocke/59adea1134bccedf5fbff42ee396093b 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
| def foo | |
| tap do | |
| $_ = 3 | |
| p $_ | |
| end | |
| p $_ | |
| end | |
| foo | |
| puts '-------------' | |
| def bar | |
| tap do | |
| _ = 3 | |
| p _ | |
| end | |
| p _ | |
| end | |
| bar |
Author
pocke
commented
Dec 18, 2016
Author
https://docs.ruby-lang.org/ja/latest/class/Kernel.html#V__
この変数はローカルスコープかつスレッドローカルです。
https://docs.ruby-lang.org/ja/latest/doc/spec=2fvariables.html#global
ローカルスコープ
通常のローカル変数と同じスコープを持ちます。つまり、 class 式本体やメソッド本体で行われた代入はその外側には影響しません。 プログラム内のすべての場所において代入を行わずともアクセスできることを除いて、通常のローカル変数と同じです。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment