Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions student.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
class Student

attr_reader :first_name, :last_name, :grade
def initialize(first_name, last_name, grade)
@first_name = first_name
@last_name = last_name
@grade = grade
end
class Student

def senior?
grade == 12
attr_reader :first_name, :last_name, :grade
def initialize(first_name, last_name, grade)
@first_name = first_name
@last_name = last_name
@grade = grade
end

def senior? #expressing intent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment adds a whole lot, I would keep it out.

grade == 12
end

def to_s
"#{last_name}, #{first_name}"
"#{last_name}, #{first_name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change here is whitespace at the end of the line -- I would not keep this. Maybe your editor can be fixed to not add whitespace?

end
end

def junior?
grade == 10
end
end

def seniors(students)
students.select { |student| student.senior? }
end

fred = Student.new("Fred", "James", 12)
def junior(students)
students.select { |student| student.junior? }
end
fred = Student.new("Fred", "James", 12 )
sarah = Student.new("Sarah", "Smith", 12)
jack = Student.new("Jack", "Gong", 11)
all_students = [fred, sarah, jack]
jack = Student.new("Jack", "Gong", 10)



all_students = [fred,sarah, jack]

puts 'Seniors'
seniors(all_students).each do |student|
puts student
end

puts ''
puts 'Juniors'
junior(all_students).each do |student|
puts student
end