[英]What is the simplest lightest way to see if there is a true statement in a hash?
If I have this hash : 如果我有此哈希:
{:thursday=>false, :friday=>false, :monday=>false, :saturday=>false, :sunday=>false, :tuesday=>false, :wednesday=>false}
What is the simplest, lightest way to identify if any of them are true 什么是确定其中是否是真正的最简单,最轻的方式
if you're looking for "pure" true
, use 如果您要寻找“ pure”
true
,请使用
hash.has_value?( true )
else use something like this 否则使用这样的东西
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.