Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
File renamed without changes.
File renamed without changes.
80 changes: 80 additions & 0 deletions seniors/student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 junior?
grade == 11
end

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

#def seniors(students)
# puts "Seniors: "
# students.select { |student| student.senior? }.each do |senior|
# puts "* #{senior}"
# end
#end

#def juniors(students)
# puts "Juniors: "
# students.select { |student| student.junior? }.each do |junior|
# puts "* #{junior}"
# end
#end

#def roll_call(students, grade)
# if ["senior","junior"].include?(grade)
# puts "#{grade.capitalize}:"
# students.select { |student| student.grade? }.each do |stu| # where grade? is either junior? or senior? based on the method param
# puts "* #{stu}"
# end
# else
# puts "Sorry you cannot call that grade"
# end
#end

def roll_call(students, grade)
puts "#{grade.capitalize}:"
if grade == "senior"
students.select { |student| student.senior? }.each do |stu|
Copy link
Member

Choose a reason for hiding this comment

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

If you want to do this, you could convert the string "senior" to a method senior? and reduce the line count.

def roll_call(students, grade)
  puts "#{grade.capitalize}:"
  students.select { |student| student.send("#{grade}?".to_sym}.each do |stu|
    puts "* #{stu}"
  end
end

puts "* #{stu}"
end
elsif grade == "junior"
students.select { |student| student.junior? }.each do |stu|
puts "* #{stu}"
end
else
puts "Sorry you cannot call that grade"
end
end


fred = Student.new("Fred", "James", 12)
sarah = Student.new("Sarah", "Smith", 12)
jack = Student.new("Jack", "Gong", 11)
all_students = [fred, sarah, jack]

#seniors(all_students).each do |student|
# puts "* #{student}\n"
#end
#seniors(all_students)
roll_call(all_students, "senior")
Copy link
Member

Choose a reason for hiding this comment

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

You could reduce this to:

%w(senior junior freshman).each do |grade|
  roll_call(all_students, grade)
end

roll_call(all_students, "junior")
roll_call(all_students, "freshman")

#juniors(all_students).each do |student|
# puts "* #{student}\n"
#end
#juniors(all_students)
30 changes: 0 additions & 30 deletions student.rb

This file was deleted.