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
47 changes: 31 additions & 16 deletions student.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
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

def senior?
grade == 12
end

def to_s
"#{last_name}, #{first_name}"
end
attr_reader :first_name, :last_name, :grade
def initialize(first_name, last_name, grade)
@first_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.

Hi!

OK, it's a small thing, but your indentation should match Ruby standards --- which are 2 spaces per indentation, rather than tabs

screenshot 11 11 13 12 20 pm

@last_name = last_name
@grade = grade
end

def senior?
grade == 12
end

def junior?
grade == 11
end


def to_s
"#{last_name}, #{first_name}"
end
end

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

def juniors(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]

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

puts "Juniors:"
juniors(all_students).each do |student|
puts student
end