New in classes

Discussion in 'Ruby' started by Amir Ebrahimifard, Aug 8, 2010.

  1. Amir Ebrahimifard, Aug 8, 2010
    #1
    1. Advertising

  2. [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"

    On Sun, Aug 8, 2010 at 6:54 PM, Amir Ebrahimifard <> 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
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >



    --
    With regards,
    Alexei Bovanenko
     
    Alexey Bovanenko, Aug 8, 2010
    #2
    1. Advertising


  3. > 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"?
    --
    Posted via http://www.ruby-forum.com/.
     
    Amir Ebrahimifard, Aug 8, 2010
    #3
  4. [Note: parts of this message were removed to make it a legal post.]

    No, you store memory location in link variable.

    On Sun, Aug 8, 2010 at 10:07 PM, Amir Ebrahimifard <> wrote:

    >
    > > 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"?
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >



    --
    With regards,
    Alexei Bovanenko
     
    Alexey Bovanenko, Aug 8, 2010
    #4
  5. [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.

    On Sun, Aug 8, 2010 at 10:14 PM, Alexey Bovanenko <>wrote:

    > No, you store memory location in link variable.
    >
    >
    > On Sun, Aug 8, 2010 at 10:07 PM, Amir Ebrahimifard <>wrote:
    >
    >>
    >> > 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"?
    >> --
    >> Posted via http://www.ruby-forum.com/.
    >>
    >>

    >
    >
    > --
    > With regards,
    > Alexei Bovanenko
    >




    --
    With regards,
    Alexei Bovanenko
     
    Alexey Bovanenko, Aug 8, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,950
    David
    Jul 22, 2005
  2. Max Derkachev
    Replies:
    4
    Views:
    674
    Jack Diederich
    May 5, 2005
  3. Isaac Rodriguez

    Are all classes new-style classes in 2.4+?

    Isaac Rodriguez, Dec 31, 2006, in forum: Python
    Replies:
    4
    Views:
    390
    Steven D'Aprano
    Dec 31, 2006
  4. Quek
    Replies:
    3
    Views:
    338
  5. Replies:
    2
    Views:
    466
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page