ruby - How should I use each_with_object on Hashes? -
i use each_with_object on hash can't figure out how should use it. here have:
hash = {key1: :value1, key2: :value2} hash.each_with_object([]) { |k, v, array| array << k } nomethoderror: undefined method `<<' nil:nilclass is possible use each_with_object on hashes? if yes, syntax?
use ():
hash.each_with_object([]) { |(k, v), array| array << k }
Comments
Post a Comment