On Fri, Mar 1, 2013 at 9:00 PM, Hans Mackowiak <[email protected]> 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
=> #<Thread:0x802a8430 dead>
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--
[email protected] |
https://groups.google.com/d/forum/ruby-talk-google?hl=en
---
You received this message because you are subscribed to the Google Groups
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.