简体   繁体   English

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

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

相关问题 通过Rails加载搜索结果的最简便方法是什么? - What is the lightest way to load search results via Rails? 在elasticsearch中处理不是最简单的方法是什么? - what is simplest way to handle not in elasticsearch? Rails:X为true时发送邮件的最简单方法 - Rails: Simplest way of sending mail when X is true 使一组方法可用于多个Rails应用程序的最简单方法是什么 - What is the simplest way to make a group of methods available to several Rails applications 使用Omniauth-Facebook Gem添加个人资料图片的最简单方法是什么? - What is the simplest way to add an profile image with the Omniauth-Facebook Gem? 在Rails中将:pluck或:collect结果转换为字符串数组的最简单方法是什么? - What is simplest way to convert :pluck or :collect results to array of strings in Rails? 在rails中使用小胡子视图模板的最简单方法是什么? - What's the simplest way to use mustache view templates in rails? 在Rails中,将哈希压缩为嵌套哈希的最佳方法是什么 - In Rails, what is the best way to compact a hash into a nested hash 从params创建新哈希的方法是什么? - What is the way to create a new hash from params? 转换此哈希的最佳方法是什么? - What would be the best way to convert this hash?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM