Definition of the "Truth" of an expression?

Possible duplicates:
Check if the Ruby object is logical.
How can I avoid the truth in Ruby?

For an array like the following (for example):

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

Is there an easier way to determine which elements are actual Boolean values ​​without resorting to this, for example?

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

Reliance on a position in an array is not an option, as it will vary from case to case.

+3
source share
1 answer

You can try it (true & value) == value. The part in parentheses always seems to return a boolean value; if the value was not originally bool, then it will not equal the result. However, the bool will be.

0
source

Source: https://habr.com/ru/post/1791136/


All Articles