我有一個簡單的回圈,它被提供一個包含多個元素的陣列,我的函式的目標是迭代每個元素,ID 的值與當前回圈中元素的 ID 和值相同'body' 是整個相同元素的。
我正在努力確保回圈重置并在每次迭代中輸入一個新元素,而不是回圈中剩余的一個或另一個。
實作這一目標的最佳方法是什么?
@data = [{ 'url' => 'https://zendesk.com/api/v2/macros/1900002708354.json',
'id' => 1_900_002_708_354,
'actions' => [{ 'field' => 'comment_value_html', 'value' => '{{email}} 360081752739' }],
'restriction' => nil },
{ 'url' => 'https://zendesk.com/api/v2/macros/360081752739.json',
'id' => 360_081_752_739,
'actions' => [{ 'field' => 'comment_value_html', 'value' => '{{IBAN}} ' }],
'restriction' => nil },
{ 'url' => 'https://zendesk.com/api/v2/macros/360081755559.json',
'id' => 360_081_755_559,
'actions' => [{ 'field' => 'comment_value_html', 'value' => '{{email}} 360081752739' }],
'restriction' => nil }]
def run_function
@data.each do |x|
@id = [x.select { |m| m['id'] }]
final_data = x
body = final_data
puts body
end
end
我的 ID 變數當前輸出為[{"id"=>1900002708354}],而我只需要數字。
uj5u.com熱心網友回復:
@data.each do |hash|
id = hash['id']
puts id
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366579.html
