2
Je cherche une solution comment écrire la fonction format
qui prendra en argument une chaîne ou un hachage imbriqué et retournera la version aplatie de celle-ci avec le chemin comme une clé.Comment changer le format des hachages imbriqués
arg = "foo"
format(arg) # => { "hash[keys]" => "foo" }
arg = {:a => "foo", :b => { :c => "bar", :d => "baz" }}
format(arg) # => { "hash[keys][a]" => "foo", "hash[keys][b][c]" => "bar", "hash[keys][b][d]" => "baz" }
Je ne pense pas que la méthode format() aurait accès au nom de votre argument. (En d'autres termes, comment formater() sait-il placer "[acteur]' après "événement"?) – sarnold