How to check if a Ruby object is a Boolean

ruby, typechecking

Solution

Simplest way I can think of:

# checking whether foo is a boolean
!!foo == foo

Problem

I can't seem to check if an object is a boolean easily. Is there something like this in Ruby? ``` true.is_a?(Boolean) false.is_a?(Boolean) ``` Right now I'm doing this and would like to shorten it: ``` some_var = rand(1) == 1 ? true : false (some_var.is_a?(TrueClass) || some_var.is_a?(FalseClass)) ```

Original source

Related problems