From: Robert Klemme Date: 2013-03-02T08:46:50+09:00 Subject: Re: Does `self` and `scope(local)` operate parallels? On Fri, Mar 1, 2013 at 9:00 PM, Hans Mackowiak wrote: > self and the "local scope" are the same Certainly not. self is an object reference which cannot be changed by the user. A scope is something that holds named object references (local variables). self can change - on method entry - when opening a class or module body - inside a block when executed via #instance_eval, #instance_exec, #class_eval or #module_eval Local scope changes - on method entry - inside blocks - inside class and module bodies irb(main):001:0> def f(x=0) irb(main):002:1> p self, local_variables.sort irb(main):003:1> 1.times do |y| irb(main):004:2* p self, local_variables.sort irb(main):005:2> end irb(main):006:1> p self, local_variables.sort irb(main):007:1> end => nil irb(main):008:0> f main [:x] main [:x, :y] main [:x] => [main, [:x]] > and they only change when you do something like instance_eval Correct. > or other stuff like Threads Wrong for self. irb(main):015:0* p self main => main irb(main):016:0> Thread.new { p self }.join main => # Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/