繁体   English   中英

查看哈希中是否存在真实语句的最简单的最简单方法是什么?

[英]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.

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