Предложить материал: @developer_tools_suggestion_bot
По вопросам рекламы: @account_managerTG
Авторы: @katetheriver
Post #404
14.9K
DE @developer_tools
module HTTPartyПеревело в
module Utils
def self.stringify_keys(hash)
return hash.transform_keys(&:to_s) if hash.respond_to?(:transform_keys)
hash.each_with_object({}) do |(key, value), new_hash|
new_hash[key.to_s] = value
end
end
end
end
HTTParty::Utils.stringify_keys({ "dog" => "Fido", "cat" => "Felix" })module defines a helper method "stringify_keys" that transforms the keys of a hash into a string. This method will transform the keys of a hash into a string if the hash responds to "transform_keys". The helper method then iterates over the hash and overwrites the keys with the corresponding values.P.S. С телефона код может поплыть немного 😅