How to add values to an array of an array in Ruby?

4
puts "Alunos\n\n"

alunos = [["Daniel: ", "Nota: 10\n\n"],["Abima: ", "Nota: 10\n\n"], ["Wilame: ", "Nota: 10\n\n"],["Felipe: ","Nota: 10\n\n"]]

puts alunos

I wonder if it is possible to add a new student with a new note as a new array in the array above, so that the parameters would have to be typed in the terminal.

    
asked by anonymous 11.11.2018 / 21:08

1 answer

4

Just use the push() method than the type array already has:

puts "Alunos\n\n"
alunos = [["Daniel: ", "Nota: 10\n\n"],["Abima: ", "Nota: 10\n\n"], ["Wilame: ", "Nota: 10\n\n"],["Felipe: ","Nota: 10\n\n"]]
alunos.push(["João: ", "Nota: 8\n\n"])
puts alunos

See running on ideone . And in Coding Ground . Also put it on GitHub for future reference .

    
11.11.2018 / 21:36