I need some help plz with my ruby project

First, i need to extend the student class, and its to be enumerable by
courses. Then, show off the new functionality supported by this
change by writing an expression that returns a list of all of the
grades a student has earned in the courses he or she has completed for
the major.

here is what I got so far…what am i missing


This class initializes a new student with ID,

and shows a list of completed courses,

and also shows a list of grades from completed courses.

class Student

include Enumerable

attr_reader :name, :id

Initializing the students name and ID.

Name = Student’s name.

ID = Student’s ID.

Initializing courses to equal a new hash.

def initialize(name, id)
@name = name
@id = id
@courses = {}

Adding a course to the set of those completed.

def add_course(code, name, grade)
@courses[code] = [code, name, grade]

Retrieving the grade for a particular course.

def get_grade(code)
([email protected][code]) && c[Grade]

Changing the grade for a course completed.

def set_grade(code, grade)
@courses[code][Grade] = grade

Providing a list of all of the courses completed.

def list_courses

def each_grade
@courses.each { |course| yeild course }

s1 = Student.new(“Eric”, “00101”)
s1.add_course(“22c:021”, “Computer Science I”, “B-”)
s1.each_grade.collect { |course| do course[2] }
puts s1

well, to start I noticed a few syntax errors, yield is misspelled, and
in the line s1.each_grade.collect { |course| do course[2] } I don’t
know what you were trying to do with ‘do course[2]’ maybe yield
course[2] and your get_grade method has c[Grade] but I don’t know what
Grade is, so maybe it should be
def get_grade(code, Grade)
([email protected][code]) && c[Grade]

maybe that might help a little


oh, and also, take out the collect on s1.each_grade and try just
passing a block to each_grade so
irb(main):009:0> s1.each_grade { |course| puts course[2] }
=> {“22c:021”=>[“22c:021”, “Computer Science I”, “B-”]}



On Oct 11, 12:04 pm, “[email protected]

class Student
attr_accessor :courses
def initialize(hash = {})
@name = hash[:name]
@id = hash[:id]
@courses = []

# if you need, write on some validations here.


class Course
def initialize(hash = {})
@code = hash[:name]
@name = hash[:id]
@grade = hash[:grade]

# if you need, write on some validations here.


s1 = Student.new :name => “Eric”, :code => “00101”
s1.courses << Course.new(:code => “22c:021”,
:name => “Computer Science I”,
:grade =>“B-”)
p s1.courses.map {|c| c[:grade] }