Results 1 to 5 of 5
Thread: New Instance of a Class Question
Feb 4, 2009, 08:13 #1
- Join Date
- Feb 2009
- 0 Post(s)
- 0 Thread(s)
New Instance of a Class Question
Hi. Ok, I am new, and I'm sure my question is very basic, but I want to learn RoR and if I don't understand something in detail it bugs the heck out of me. So hopefully someone can help.
I'm going through the Sitepoint book and come to this example:
@@number_of_cars = 0
@@number_of_cars += 1
I created 4 car objects and then did a Car.count and got 4, so it works as advertised, but I have two questions.
1. with the line of code @@number_of_cars = 0, why isn't that variable getting reset to 0 each time I instantiate a new car object? It seems to me it would, but obviously it isn't. Which is a good thing, but I don't udnerstand why it isn't resetting the variable to 0 with each new instance.
2. I assume it is just 'convention' and the name 'initialize' that makes that method run each time a new instance of the object is created. Correct?