# Execution scope of Ruby artifacts running outside of an obje

**URL:** <https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607>\
**Category:** Ruby\
**Created:** [March 21, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607 "2007-03-21T16:05:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Griff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@Griff](https://www.ruby-forum.com/u/Griff)\
**Post date:** [March 21, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607/1 "2007-03-21T16:05:39Z")

</div>

Hi folks,

What is the scope of execution of a plain old Ruby script?

For example, if you write a script that does not define any classes  
and you use reflection to get the current class, you discover that it  
is “Object”.

Eg on Windows:

echo puts “#{self.class}” \> temp.rb  
ruby temp.rb  
Object

I am interested in where this behavior is defined. I didn’t see any  
mention of this in the Pickaxe2 book, but I could have overlooked it.

---

<div class="post-metadata">

**Author:** ![Griff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@Griff](https://www.ruby-forum.com/u/Griff)\
**Post date:** [March 21, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607/2 "2007-03-21T16:31:46Z")

</div>

Griff wrote:

> echo puts “#{self.class}” \> temp.rb  
> ruby temp.rb  
> Object
> 
> I am interested in where this behavior is defined. I didn’t see any  
> mention of this in the Pickaxe2 book, but I could have overlooked it.

From the Pickaxe, 2nd Edition, page 11:  
“Everything you manipulate is an object, and the results of those  
manipulations are themselves objects.”

Every single thing you use, is derived, in the end from Object, the  
great-grandfather of everything Ruby. At least that is how I’ve  
understood the Pickaxe in that regard.

On the other hand, I only hack Ruby into my keyboard, and don’t hack  
Ruby. 😉

Cheers

-Phil

---

<div class="post-metadata">

**Author:** ![Griff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@Griff](https://www.ruby-forum.com/u/Griff)\
**Post date:** [March 21, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607/3 "2007-03-21T21:53:39Z")

</div>

On Thu, Mar 22, 2007 at 12:05:07AM +0900, Griff wrote:

> Object
> 
> I am interested in where this behavior is defined. I didn’t see any  
> mention of this in the Pickaxe2 book, but I could have overlooked it.

This top-level object is called “main” (try puts self.inspect, or indeed  
look at the prompt which irb gives)

There is a brief description in Pickaxe2 on page 376 (PDF page 404)

---

<div class="post-metadata">

**Author:** ![Griff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@Griff](https://www.ruby-forum.com/u/Griff)\
**Post date:** [March 21, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/execution-scope-of-ruby-artifacts-running-outside-of-an-obje/89607/4 "2007-03-21T21:57:40Z")

</div>

Sorry, Page not found!

> There is a brief description in Pickaxe2 on page 376 (PDF page 404)

I couldn’t resist.
