-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_directory_Step7.rb
executable file
·54 lines (47 loc) · 1.82 KB
/
copy_directory_Step7.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#Student names in an array
# students = [
# {name: "Dr. Hannibal Lecter", cohort: :november},
# {name: "Darth Vader", cohort: :november},
# {name: "Nurse Ratched", cohort: :november},
# {name: "Michael Corleone", cohort: :november},
# {name: "Alex DeLarge", cohort: :november},
# {name: "The Wicked Witch of the West", cohort: :november},
# {name: "Terminator", cohort: :november},
# {name: "Freddy Krueger", cohort: :november},
# {name: "The Joker", cohort: :november},
# {name: "Joffrey Baratheon", cohort: :november},
# {name: "Norman Bates", cohort: :november}
# ]
def input_students
puts "Please enter the names of the students"
puts "To finish, just hit return twice" #So 'name' will be empty, and while loop breaks
students = []
name = gets.chomp
while !name.empty? do
#New hash pushed to students array
#key = name: = value of name, value = cohort: :november (hardcoded)
students << {name: name, cohort: :november}
puts "Now we have #{students.count} students"
name = gets.chomp
end
students #return array of hashes of the students
end
#Print list of students
def print_header
puts "The students of Villans Academy"
puts "-------------"
end
#Iterate over the students array to print each name
def print(students) #names placeholder
students.each do |student|
puts "#{student[:name]} (#{student[:cohort]} cohort)"
end
end
#Finally, we print the total number of students using the array.count method
def print_footer(names) #names placeholder
puts "Overall, we have #{names.count} great students"
end
students = input_students #The outcome of the method input_students
print_header
print(students) #Again, outcome of method input_students
print_footer(students) #Outcome of method input_students