# Field Scope

**URL:** <https://www.ruby-forum.com/t/field-scope/90250>\
**Category:** Ruby\
**Created:** [January 5, 2006, 1:33pm UTC](https://www.ruby-forum.com/t/field-scope/90250 "2006-01-05T13:33:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![forest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://www.ruby-forum.com/u/forest)\
**Post date:** [January 5, 2006, 1:33pm UTC](https://www.ruby-forum.com/t/field-scope/90250/1 "2006-01-05T13:33:14Z")

</div>

what is the scope of @run field in the code below. Is it module static  
? If not, how module static methods can access it ?

module Test  
module Unit  
def self.run=(flag)  
@run = flag  
end

```
def self.run?
  @run ||= false
end

```

end  
end

at\_exit do  
unless $! || Test::Unit.run?  
exit Test::Unit::AutoRunner.run($0 != “-e” && $0)  
end  
end

---

<div class="post-metadata">

**Author:** ![forest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://www.ruby-forum.com/u/forest)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/field-scope/90250/2 "2006-01-05T17:44:28Z")

</div>

On Thu, 05 Jan 2006 12:28:07 -0000, forest [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> @run ||= false
> end
> 
> ```
> 
> end  
> end

Forget about static and all that, and remember that modules are objects  
too. Test::Unit is just a constant, that references the Module instance  
for that module.

Does this make it any clearer?

```
Test::Unit.run = 'Hmm...'
Test::Unit.instance_eval { @run } # => "Hmm..."

a = Test::Unit
a.instance_eval { @run } # => "Hmm..."

```

---

<div class="post-metadata">

**Author:** ![forest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://www.ruby-forum.com/u/forest)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/field-scope/90250/3 "2006-01-05T17:44:44Z")

</div>

Thanks a lot, it explains everything.

Funny that somewhere i read that ruby follows Least Surprise Paradigm,  
but personally me i was deeply surprised several times, while learning  
it 🙂

---

<div class="post-metadata">

**Author:** ![forest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f1d935/32.png) [@forest](https://www.ruby-forum.com/u/forest)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/field-scope/90250/4 "2006-01-05T17:44:45Z")

</div>

On Thu, 05 Jan 2006 14:15:33 -0000, forest [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks a lot, it explains everything.
> 
> Funny that somewhere i read that ruby follows Least Surprise Paradigm,  
> but personally me i was deeply surprised several times, while learning  
> it 🙂

I feel the same way, but I realise now that I feel that way because I  
expect Ruby to be as convoluted and… well, surprising, as other  
languages. It surprises me by how unsurprising it is (_most of the  
time_)  
😉
