gpt4 book ai didi

ruby - 确定表达式的 "Truthiness"?

转载 作者:数据小太阳 更新时间:2023-10-29 08:13:48 26 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
Check if Ruby object is a Boolean
How can I avoid truthiness in Ruby?

给定如下数组(例如):

[3, false, "String", 14, "20-31", true, true, "Other String"]

例如,是否有更简单的方法来确定哪些元素是实际 bool 值而不求助于此?

value === TrueClass || value === FalseClass

依赖于数组中的位置不是一种选择,因为它会因情况而异。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com