[英]What is the simplest lightest way to see if there is a true statement in a hash?
如果我有此哈希:
{:thursday=>false, :friday=>false, :monday=>false, :saturday=>false, :sunday=>false, :tuesday=>false, :wednesday=>false}
什么是確定其中是否是真正的最簡單,最輕的方式
如果您要尋找“ pure” true
,請使用
hash.has_value?( true )
否則使用這樣的東西
hash.detect{|key,value| value }
# or
hash.detect{|key,value| !!value }
# or even
if_nil = Proc.new{ "this will be called if no matching value is found" }
hash.detect( if_nil ) {|key,value| !!value }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.