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
17 changes: 16 additions & 1 deletion student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def senior?
grade == 12
end

def junior?
grade <= 11 and grade > 8
Copy link
Member

Choose a reason for hiding this comment

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

In Ruby, while "and" exists, it's not quite a synonym for "&&" --- so, in comparisons like this, you should use "&&"

More information on the topic: http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! You saved me ahead from a lot of trouble!

end

def to_s
"#{last_name}, #{first_name}"
end
Expand All @@ -20,11 +24,22 @@ def seniors(students)
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 "\n"
puts "Juniors"
juniors(all_students).each do |student|
puts " * #{student}"
end
puts "\n"