Challenge 3: A Class Method Counter — Solution class Book attr_accessor :title, :author, :pages @@count = 0 # class variable, shared across every instance def initialize(title, author, pages) @title = title @author = author @pages = pages @@count += 1 end def self.total_books @@count end end Book.new("The Hobbit", "J.R.R. Tolkien", 310) Book.new("Dune", "Frank Herbert", 412) Book.new("1984", "George Orwell", 328) puts Book.total_books =begin Output: 3 Notes: - @@count (double @) is a class variable — one single value shared by the class itself and every instance, unlike @count (single @) which would be a separate instance variable per object. - Every call to Book.new runs initialize, which increments @@count by 1 as a side effect of constructing a new instance. - self.total_books is a class method (defined with self., as covered in the chapter) — it's called on Book directly, Book.total_books, with no instance required, and simply returns the current shared count. =end