我的脚本有:
my_hash = {'key1' => 'value1', 'key2' => ['value2', 'value3']}
my_array = ["text...#{variable1}", "text...#{variable2}", "text...#{variable3}"]
my_hash['key2'] = my_array
我收到:[]=': can't convert Hash into String (TypeError)
。
如何更新key2
的整个数组?
答案 0 :(得分:1)
new_array = ['value5']
hash = {
'key1' => 'value1',
'key2' => ['value2', 'value3']
}
hash['key2'] = new_array