mercredi 18 mai 2022

Ruby; How can I update the nested hashes in this one?

Sorry, it's a little bit too long. I need to change the status of :hero and :heroine to "dead"

def update_status
   epic_tragedy = {
      :montague => {
         :patriarch => {name: "Lord Montague", age: "53"},
         :matriarch => {name: "Lady Montague", age: "54"},
         :hero => {name: "Romeo", age: "15", status: "alive"},
         :hero_friends => [
            {name: "Benvolio", age: "17", attitude: "worried"},
            {name: "Mercutio", age: "18", attitude: "hot-headed"}
         ]
      },
      :capulet => {
         :patriarch => {name: "Lord Capulet", age: "50"},
         :matriarch => {name: "Lady Capulet", age: "51"},
         :heroine => {name: "Juliet", age: "15", status: "alive"},
         :heroine_friends => [
         {name: "Steven", age: "30", attitude: "confused"},
         {name: "Nurse", age: "44", attitude: "worried"}
         ]
      }
   }

I did add the code below inside the method but it shows error.

epic_tragedy[:montague][:hero][:status] = "dead"

epic_tragedy[:capulet][:hero][:status] = "dead"

Is there any additional step before I put those lines?

Aucun commentaire:

Enregistrer un commentaire