# Truth value evaluating of an object

**URL:** <https://www.ruby-forum.com/t/truth-value-evaluating-of-an-object/118523>\
**Category:** Ruby\
**Created:** [October 28, 2007, 2:30am UTC](https://www.ruby-forum.com/t/truth-value-evaluating-of-an-object/118523 "2007-10-28T02:30:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/48db29/32.png) [@Byron](https://www.ruby-forum.com/u/Byron)\
**Post date:** [October 28, 2007, 2:30am UTC](https://www.ruby-forum.com/t/truth-value-evaluating-of-an-object/118523/1 "2007-10-28T02:30:42Z")

</div>

I know ruby treat an object as false whenever it is nil or false.  
However, I wonder if there are any other ways to change this behavior.

For example, I define a class called AreYouOk.  
class AreYouOk  
def initialize(ok)  
@ok = ok  
end  
end

x = AreYouOk.new(false)  
puts “you are ok” if x

Since x is not nil, ruby prints " you are ok".  
However, I want ruby to make the decision based on the @ok instance  
variable. Are there any ways to do that?

I know that there is a method called **bool** in Python. You can  
define your **bool** method in your class. The truth value of an  
object is based on the return value of **bool**. Does ruby provide  
similar mechanism?
