How to check if a Ruby object is a Boolean

Solution 1:

Simplest way I can think of:

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

Solution 2:

I find this to be concise and self-documenting:

[true, false].include? foo

If using Rails or ActiveSupport, you can even do a direct query using in?

foo.in? [true, false]

Checking against all possible values isn't something I'd recommend for floats, but feasible when there are only two possible values!