将数组值转换为Ruby中的哈希值[关闭]

问题描述 投票:-1回答:1
我有两个数组,

array_One = ["RESPONSE_TEXT_CONTENT_TYPE", "RESPOSNSE_KEY"] array_Two = ["RESPONSE_TEXT_CONTENT_TYPE = 'responseTextContentType'\n"] ["CURRENT_USER_ID = 'careUserId'\n"] ["RESPOSNSE_KEY = 'responseKey'\n" ]

我需要将arra_Two转换为某个哈希值。如下所示,

hash_One = ["RESPONSE_TEXT_CONTENT_TYPE" =>responseTextContentType, "CURRENT_USER_ID" => careUserId "RESPOSNSE_KEY" => responseKey]

我可以采取什么方式
arrays ruby hash
1个回答
-1
投票
RESPONSE_TEXT_CONTENT_TYPE = 20 RESPOSNSE_KEY = 5 test = 10 x = 5 arr1 = [RESPONSE_TEXT_CONTENT_TYPE,test,RESPOSNSE_KEY,x] arr2 = [test,x,'local',123,RESPONSE_TEXT_CONTENT_TYPE] arr3 = arr1 & arr2 puts arr3.inspect
© www.soinside.com 2019 - 2024. All rights reserved.