New in classes

  • Thread starter Amir Ebrahimifard
  • Start date
A

Alexey Bovanenko

[Note: parts of this message were removed to make it a legal post.]

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"
 
A

Amir Ebrahimifard

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"?
 
A

Alexey Bovanenko

[Note: parts of this message were removed to make it a legal post.]

No, you store memory location in link variable.
 
A

Alexey Bovanenko

[Note: parts of this message were removed to make it a legal post.]

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

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