Execution scope of Ruby artifacts running outside of an object (plain old script)?

G

Griff

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.
 
C

cmdjackryan

Griff said:
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.
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
 
B

Brian Candler

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.

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top