简体   繁体   English

在哈希内访问哈希内的数组(添加新值)

[英]Accessing array within a hash within a hash (adding new values)

Thank you for the help in advance! 预先感谢您的帮助! I'd like to add or push a value into my array which is currently within a person hash and task hash. 我想将值添加或推入当前位于人员哈希和任务哈希中的数组中。

Look below at the add task section task.merge! 看下面的添加任务部分task.merge!

task = {
"person1" => { 
    :high => ["email", "phone","email2","talk","meeting"], 
    :mid => ["task1","task2"], 
    :low => ["task1","task2"] },

"person2" => { 
    :high => ["email", "phone","email2","talk","meeting"], 
    :mid => ["task1","task2"], 
    :low => ["task1","task2"] },

"person3" => { 
    :high => ["email", "phone","email2","talk","meeting"], 
    :mid => ["task1","task2"], 
    :low => ["task1","task2"] },
}

puts task["person1"][:high][0]

# create task
    #create new person hash within task hash
    #already have :high, :mid, & :low hash
# add task
    #add a task to the array within either high,mid, or low
    task.merge!("person1" => {:high => "#{new_task}")
# remove task
    #delete method
task.merge! "person1" => {:high => "#{new_task}"}

You simply had an error there. 您只是在那里有一个错误。 I removed the parenthesis to make it maybe a little more obvious. 我删除了括号以使其更明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM