Why class-level behavior matters
📖 Scenario: Imagine you are creating a simple system to track books in a library. Each book has a title and an author. You want to count how many books have been created in total, no matter which book it is.
🎯 Goal: You will build a Ruby class Book that keeps track of how many book objects have been created using class-level behavior.
📋 What You'll Learn
Create a class called
BookAdd an instance method
initialize that takes title and author parametersAdd a class variable
@@count to count how many books have been createdIncrement
@@count each time a new Book is createdAdd a class method
self.count that returns the total number of books createdCreate at least two
Book objects with given titles and authorsPrint the total number of books created using the class method
💡 Why This Matters
🌍 Real World
Counting objects like books, users, or orders is common in software to track totals or limits.
💼 Career
Understanding class-level behavior is important for designing classes that manage shared data or resources in Ruby applications.
Progress0 / 4 steps