![]() | episode 2 - class variables vs. class level instance variables |
|
20 Apr 2010, 11:18
Fred Boldireff (4 posts) |
Hello Dave, In episode 2 (00:22:15) you mention a “good use” of I have checked with a simple: ... that @count is indeed not accessible to instances of Dave (get_count method called on those instances would return nil), so @count does behave like a class variable (I understand it’s because it’s defined right after class Dave, at a point in code where the current object is the class Dave object).
But still, why do class variables ( Anyway, a thousand thanks for this enlightening serie! |
|
20 Apr 2010, 13:37
Dave Thomas (231 posts) |
Remember that instance variables are always accessed in the object referenced by @@variable style class variables have a different semantics, and should be avoided. |
|
20 Apr 2010, 14:36
Fred Boldireff (4 posts) |
Thank you so much for your reply. I think I get it now, and when you write ” Cheers, Fred. |
|
21 Apr 2010, 13:28
Dave Thomas (231 posts) |
In reality, |
|
23 Apr 2010, 00:08
Fred Boldireff (4 posts) |
Neither did I, but I was just curious. I found an article summing up the subject (class variables vs. class level instance variables), with some interesting metaprogramming techniques that I can now decrypt thanks to your videocast. It seems the troubles arise with inheritance… |
| You must be logged in to comment |

