Hello, Space Explorer! Today, we're delving into an essential topic in Ruby: managing data using arrays.
We’ll practice this by building a simple Student Management System that tracks students and their grades. Using arrays in Ruby, we’ll see how to efficiently organize and access data, just as we might in real-world applications. Ready to dive in? Let’s get started!
To achieve our goal, we’ll need three key methods within our class:
add_student(name, grade): Adds a new student and their grade to the list. If the student already exists, their grade will be updated.get_grade(name): Retrieves the grade for a student by their name. If the student isn’t found, it returnsnil.remove_student(name): Removes a student from the list by their name. It returnstrueif the student was successfully removed andfalseif the student doesn’t exist.
Sound straightforward? Fantastic! Let’s walk through each method step-by-step.
First, we’ll define our StudentManager class, which will use an array to manage students and their grades.
