Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, January 19, 2013

Codecademy Sample Solution: Twice the @, Twice as Classy



class Person
  # Set your class variable to 0 on line 3
  @@people_count = 0
 
  def initialize(name)
    @name = name
    # Increment your class variable on line 8
    @@people_count += 1
  end
 
  def self.number_of_instances
    # Return your class variable on line 13
    return @@people_count
  end
end

matz = Person.new("Yukihiro")
dhh = Person.new("David")

puts "Number of Person instances: #{Person.number_of_instances}"

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts