Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 最简单最简单的方法是什么来判断散列中是否有真语句?_Ruby On Rails - Fatal编程技术网

Ruby on rails 最简单最简单的方法是什么来判断散列中是否有真语句?

Ruby on rails 最简单最简单的方法是什么来判断散列中是否有真语句?,ruby-on-rails,Ruby On Rails,如果我有这个散列: {:thursday=>false, :friday=>false, :monday=>false, :saturday=>false, :sunday=>false, :tuesday=>false, :wednesday=>false} 最简单、最简单的方法是什么来确定它们中的任何一个是否为真 hash.has_value?( true ) 否则就用这个 hash.detect{|key,value| value } #

如果我有这个散列:

{:thursday=>false, :friday=>false, :monday=>false, :saturday=>false, :sunday=>false, :tuesday=>false, :wednesday=>false}
最简单、最简单的方法是什么来确定它们中的任何一个是否为真

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 }
如果要查找“纯”
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 }