newbie help : Ruby Processin

  • Thread starter Jerome david Sillinger
  • Start date
J

Jerome david Sillinger

Hello, Looking at the code in the attached file can someone please
explain to me in simple terms why in the method
------------------------------------------------------
class Example81 < Processing::App
def setup
size screen.width/2, screen.height/2
#Initialize car object
@my_car = Car.new(self)
end
------------------------------------------------------
why is 'self' is passed as a parameter also why does the initializer for
the Car class look like this?
------------------------------------------------------
class Car #define a class below the rest of the program

def initialize(app)
------------------------------------------------------

I understand that 'self' refers to the current object and objects use
them to call methods defined within themselves.

Please see the attachement for a better picture of the context of the
code

Thanks

JD

Attachments:
http://www.ruby-forum.com/attachment/4441/example81.rb
 
P

Philliam Auriemma

Not sure I understand teh question, but in doing the setup method of
an Example81 object which inherits from Processing::App, you turn the
instance variable @my_car into a Car object by making a new one, with
the parameter of the new Car as the instance of the Example81 class
that you are working with.
 
J

Jerome David Sallinger

Hello Philliam, Thank you for you response. I think that your response
has given me valuable insight into the code I attached earlier in that I
now understand that the keywork 'self' refers to the object that we are
currently in. But what is actually passed, a copy, or a reference to an
instance of Example81?

When we look at @app in the Car class what are .width and .height etc..
Sureley they would be methods of Example81 that have been inherited from
the App superclass. Is this a fair assumption to make?

JD
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top