# Re: nil.to\_s != "nil"

**URL:** <https://www.ruby-forum.com/t/re-nil-to-s-nil/73872>\
**Category:** Ruby\
**Created:** [October 27, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/re-nil-to-s-nil/73872 "2006-10-27T18:40:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 27, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/re-nil-to-s-nil/73872/1 "2006-10-27T18:40:02Z")

</div>

From: Eero S. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> true.to\_s # =\> “true”  
> false.to\_s # =\> “false”  
> nil.to\_s # =\> “”
> 
> “” is not a valid representation of nil. “nil” is.

How do you define “valid”?  
obj == eval(obj.to\_s)  
?

If that is your criteria, then:  
a) Most to\_s aren’t “valid”, and  
b) #inspect is a better shot

irb(main):001:0\> [true, false, nil, [], “Hello”, 1.24 ].each{ |x|  
irb(main):002:1\* p eval( x.inspect )  
irb(main):003:1\> }  
true  
false  
nil  
[]  
“Hello”  
1.24
