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
···
From: Eero Saynatkari [mailto:ruby-ml@kittensoft.org]