# Is main an object or a method?

**URL:** <https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096>\
**Category:** Ruby\
**Created:** [April 16, 2007, 1:58am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096 "2007-04-16T01:58:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 1:58am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/1 "2007-04-16T01:58:25Z")

</div>

I was surprised, while reading Satish T.'s ruby tutorial, to discover  
that main is actually a method – at least, it is according to the Open  
Classes section of the tutorial:

[Learn How to Blog and Build Websites for Profit!](http://rubylearning.com/satishtalim/ruby_open_classes.html)

To quote:

Please note that self.class refers to Object and self refers to method  
main. Therefore while running this program you are executing the main  
method of object Object.

Is that correct? I would have thought main was an instance of Object,  
and thus was an object itself, not a method of class Object. Using  
Object.methods within irb doesn’t list a main method, so I’m skeptical.

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 3:07am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/2 "2007-04-16T03:07:28Z")

</div>

Hi Chad,

I stand corrected.

That was the impression I was carrying when I started learning Ruby (and  
coming from a long Java background). I realized my folly a long time  
back  
and corrected my statement here -  
[http://sitekreator.com/satishtalim/first\_program.html](http://sitekreator.com/satishtalim/first_program.html)

but forgot to correct the same at the url you mention. Thanks for  
pointing  
it out - it’s now corrected.

Satish

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 3:15am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/3 "2007-04-16T03:15:29Z")

</div>

indeed, main is a method of class Thread  
check it with ri  
ri main  
gives you  
Thread.main  
which returns the main thread for the process.

self is the current object, a synonym if you will.  
Defined as the receiver object of the current method.

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 4:16am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/4 "2007-04-16T04:16:32Z")

</div>

On Apr 16, 4:57 am, Chad P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> method of object Object.
> 
> Is that correct? I would have thought main was an instance of Object,  
> and thus was an object itself, not a method of class Object. Using  
> Object.methods within irb doesn’t list a main method, so I’m skeptical.
> 
> –  
> CCD CopyWrite Chad P. [[http://ccd.apotheon.org](http://ccd.apotheon.org)]  
> Brian K. Reid: “In computer science, we stand on each other’s feet.”

Hi Chad,

I stand corrected.

That was the impression I was carrying when I started learning Ruby  
(and coming from a long Java background). I realized my folly a long  
time back and corrected my statement here -  
[http://sitekreator.com/satishtalim/first\_program.html](http://sitekreator.com/satishtalim/first_program.html)

but forgot to correct the same at the url you mention. Thanks for  
pointing it out - it’s now corrected.

Satish

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 6:21am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/5 "2007-04-16T06:21:39Z")

</div>

On Mon, Apr 16, 2007 at 10:14:49AM +0900, John J. wrote:

> indeed, main is a method of class Thread  
> check it with ri  
> ri main  
> gives you  
> Thread.main  
> which returns the main thread for the process.
> 
> self is the current object, a synonym if you will.  
> Defined as the receiver object of the current method.

Roseanne’s evidence seems to corroborate my impression – that main (in  
the context of the main scope of a Ruby program) is an object of type  
Object, not a method. I believe the Thread.main method is a method that  
just happens to have the same name as the main instance of Object.

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 6:23am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/6 "2007-04-16T06:23:39Z")

</div>

On Mon, Apr 16, 2007 at 11:15:10AM +0900, smtalim wrote:

> > main. Therefore while running this program you are executing the main  
> > Hi Chad,
> 
> I stand corrected.
> 
> That was the impression I was carrying when I started learning Ruby  
> (and coming from a long Java background). I realized my folly a long  
> time back and corrected my statement here -  
> [- Log In](http://sitekreator.com/satishtalim/first_program.html)
> 
> but forgot to correct the same at the url you mention. Thanks for  
> pointing it out - it’s now corrected.

I’m glad I could be of help, then. Thanks for the tutorial, by the way.  
I find that, even when I’m experienced with a given language beyond the  
target audience of a given tutorial, every halfway decent programming  
tutorial has something to teach me – and yours has helped.

---

<div class="post-metadata">

**Author:** ![cpeterson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58f4c7/32.png) [@cpeterson](https://www.ruby-forum.com/u/cpeterson)\
**Post date:** [April 16, 2007, 4:04am UTC](https://www.ruby-forum.com/t/is-main-an-object-or-a-method/92096/7 "2007-04-16T04:04:39Z")

</div>

Chad P. wrote:

> I was surprised, while reading Satish T.'s ruby tutorial, to discover

```auto
E:\ex>ruby -e "puts self.kind_of?(Class)"
false

E:\ex>ruby -e "puts self.kind_of?(Module)"
false

E:\ex>ruby -e "puts self.kind_of?(Object)"
true

E:\ex>ruby -e "puts self"
main

E:\ex>ruby -e "puts self.class"
Object
```
