mardi 9 mai 2023

ruby combine hash related key

I want to combine related key for example:

my_hash = {key_a: "value a", key_b: "value b", key_c: "value c"}

I want the result to be:

{ key:
  [
    { a: "value a" },
    { b: "value b" },
    { c: "value c" }
  ]
}

It can be easily do that by getting each key explicitly but the problem is, it can define dynamic key.

THE PROBLEM is key_ is can be any, you can't determine what is after key_. It can be key_r, key_w, key_z

Aucun commentaire:

Enregistrer un commentaire