# New in classes

**URL:** <https://www.ruby-forum.com/t/new-in-classes/192926>\
**Category:** Ruby\
**Created:** [August 8, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926 "2010-08-08T16:54:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/1 "2010-08-08T16:54:51Z")

</div>

Hi  
In the attached code what is the meaning of colored part of code? what  
is the meaning those codes that showed when I wrote “Test.new” and  
“variable = Test.new” ?

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 7:44pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/2 "2010-08-08T19:44:53Z")

</div>

Amir E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi  
> In the attached code what is the meaning of colored part of code? what  
> is the meaning those codes that showed when I wrote “Test.new” and  
> “variable = Test.new” ?
> 
> Attachments:  
> [http://www.ruby-forum.com/attachment/4926/capture.jpg](http://www.ruby-forum.com/attachment/4926/capture.jpg)

You said “please instantiate the Test class”. irb said “Okay, I did  
that; I made a new instance of Test, and here is its memory address so  
you can keep track of this instance later if you need to.”

Then you said “Well, that was stupid; I instantiated the Test class, but  
I didn’t do anything about capturing that instance, so I have no way to  
refer to it. So this time, please instantiate the Test class and point  
to that instance with a variable called variable.” irb said “Okay, I did  
that; I made a new instance of Test, and here is its memory address  
(pointed to by variable) so you can keep track of this instance later if  
you need to. By the way you can see from the address that this is a  
different instance from the one we made earlier.”

If you are a total beginner with the notion of classes and instances (it  
looks like you are), this might help you:

[http://www.apeth.com/rubyIntro/justenoughruby.html](http://www.apeth.com/rubyIntro/justenoughruby.html)

m.

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 7:57pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/3 "2010-08-08T19:57:11Z")

</div>

Hi!

You have a class. Next, Test.new - it’s a instantiation, you create the  
real  
object in memory from you class.  
You need to store that instance in variable to work with it, f.e

class Test  
def test  
put “Hello”  
end  
end

v=Test.new // I create instance and store it in variable  
v.test // call method test

To work with real object you need have link for it. This link is a  
variable  
“v”

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 8:07pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/4 "2010-08-08T20:07:02Z")

</div>

> You said “please instantiate the Test class”. irb said “Okay, I did  
> that; I made a new instance of Test, and here is its memory address so  
> you can keep track of this instance later if you need to.”
> 
> Then you said “Well, that was stupid; I instantiated the Test class, but  
> I didn’t do anything about capturing that instance, so I have no way to  
> refer to it. So this time, please instantiate the Test class and point  
> to that instance with a variable called variable.” irb said “Okay, I did  
> that; I made a new instance of Test, and here is its memory address  
> (pointed to by variable) so you can keep track of this instance later if  
> you need to. By the way you can see from the address that this is a  
> different instance from the one we made earlier.”

you means that in second time that I make an object I named a memory  
location to “variable”?

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 8:20pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/5 "2010-08-08T20:20:01Z")

</div>

When you create a instance of object you need to store link to it.

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 8, 2010, 8:15pm UTC](https://www.ruby-forum.com/t/new-in-classes/192926/6 "2010-08-08T20:15:20Z")

</div>

No, you store memory location in link variable.
