我有散列的數組:如何檢測值在哈希陣列
@array = [{:id => "1", :status=>"R"},
{:id => "1", :status=>"R"},
{:id => "1", :status=>"B"},
{:id => "1", :status=>"R"}]
如何檢測,是否包含在狀態「B」的哈希值?像簡單的數組:
@array = ["R","R","B","R"]
puts "Contain B" if @array.include?("B")
如果我關心如何找到符合條件的值,我只會真的在'any'上使用'detect',但它肯定可以用作謂詞方法。 (1) –