我有一个数组:
array = [{"number" => "7", "disk" => "70"},{"number" => "12", "disk" => "150", "global" => "yes"},{"number" => "8", "disk" => "250", "global" => "yes"}]
我想定义一个包含第一个" global"的值的字符串。关键外观。我知道如何循环该哈希,但我无法弄清楚如何定义该键的第一个外观。
答案 0 :(得分:1)
array.each { |h| break h["global"] if h["global"] }