Check if Ruby object is a Boolean
Posted
by viatropos
on Stack Overflow
See other posts from Stack Overflow
or by viatropos
Published on 2010-06-12T09:57:56Z
Indexed on
2010/06/12
10:02 UTC
Read the original article
Hit count: 239
ruby
|typechecking
Can't seem to find how 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))
© Stack Overflow or respective owner