Comment devrais-je utiliser each_with_object sur Hashes?

Je voudrais utiliser each_with_object sur un hash mais je n’arrive pas à comprendre comment l’utiliser. Voici ce que j’ai:

 hash = {key1: :value1, key2: :value2} hash.each_with_object([]) { |k, v, array| array << k } NoMethodError: undefined method `<<' for nil:NilClass 

Est-il possible d’utiliser each_with_object sur les hachages? Si oui, quelle est la syntaxe?

Utiliser () :

 hash.each_with_object([]) { |(k, v), array| array << k } 

J’ai une idée à ce sujet. Vous pouvez utiliser

 Hash.each_with_index do |e, index| // do something with e. E is aray. e have 2 items. // First item of e is key. // Last item of e is value. // index start with 0. end