I need to output my hashes to a table. The data have an array called students
, which has hashes with keys "first_name"
, "last_name"
, and "grade_level"
.
This is the code I have.
students = []
# Dummy Inputs.
students = [
{
"first_name" => "Bob",
"last_name" => "Builder",
"grade_level" => 4
},
{
"first_name" => "Test",
"last_name" => "Buida",
"grade_level" => 3
},
{
"first_name" => "Senior",
"last_name" => "June",
"grade_level" => 5
},
{
"first_name" => "John",
"last_name" => "Smith",
"grade_level" => 2
},
{
"first_name" => "Me",
"last_name" => "Developer",
"grade_level" => 11
}]
...
puts "\n--------------- \n" +
"| CLASS ROSTER \n" +
"--------------- \n" # Felt lazy to add them individual put
puts "First Name Last Name Grade Level\n"
students.each do |student|
puts "#{student["first_name"]} #{student["last_name"]} #{student["grade_level"]}"
I used tab to set the column. Sometimes, it glitches like below.
Is there any way to make this better?