Key Concepts

Review core concepts you need to learn to master this subject

Ruby Class Variables

class Child @@children = 0 def initialize(name, birth_year) @name = name @birth_year = birth_year @@children +=1 end def self.children_added return @@children end end naomi ="Naomi", 2006) bertha ="Bertha", 2008) puts Child.children_added # => 2

In Ruby, class variables are attached to the class in which they are declared. A class variable should be declared with two @ symbols preceding it.

Object-Oriented Programming I
Lesson 1 of 2