# Non empty string complained to be 'nil' in equality check

**URL:** <https://www.ruby-forum.com/t/non-empty-string-complained-to-be-nil-in-equality-check/186792>\
**Category:** Ruby\
**Created:** [April 12, 2010, 1:37pm UTC](https://www.ruby-forum.com/t/non-empty-string-complained-to-be-nil-in-equality-check/186792 "2010-04-12T13:37:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![old\_as\_a\_fossil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/54ee81/32.png) [@old\_as\_a\_fossil](https://www.ruby-forum.com/u/old_as_a_fossil)\
**Post date:** [April 12, 2010, 1:37pm UTC](https://www.ruby-forum.com/t/non-empty-string-complained-to-be-nil-in-equality-check/186792/1 "2010-04-12T13:37:31Z")

</div>

I have the below code  
response = Net::HTTP.start(url.host, url.port) do  
|http|  
http.request(request)  
end  
exp\_code = 450  
if(response.code.to\_i != exp\_code)  
raise StandardError, “Expected #{exp\_code} Received  
#{response.code.to\_i}”  
end  
exp\_msg = ‘Blocked By Parental Controls’  
puts ‘Received status msg: #{response.message}’  
if(response.message != exp\_msg)  
raise StandardError, “Expected #{exp\_msg} Received  
#{response.message}”  
end

The received response is  
HTTP/1.1 450 Blocked By Parental Controls^M  
Date: Mon, 12 Apr 2010 10:28:15 GMT^M  
P3P: policyref=“[http://p3p.yahoo.com/w3c/p3p.xml](http://p3p.yahoo.com/w3c/p3p.xml)”, CP=“CAO DSP COR CUR  
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi  
PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV”^M  
cache-control: public,must-revalidate^M  
Content-Length: 0^M  
Connection: close^M  
Content-Type: ^M  
^M

The “puts” statement is printing  
Received status msg: Blocked By Parental Controls

But the next statement for inequality check fails with  
can’t convert nil to string

However for a different case, where the response is  
HTTP/1.1 200 OK^M  
Date: Mon, 12 Apr 2010 10:28:29 GMT^M  
P3P: policyref=“[http://p3p.yahoo.com/w3c/p3p.xml](http://p3p.yahoo.com/w3c/p3p.xml)”, CP=“CAO DSP COR CUR  
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi  
PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV”^M  
cache-control: public,must-revalidate^M  
Content-Length: 0^M  
Connection: close^M  
Content-Type: ^M  
^M

and I have the ruby code as:  
exp\_msg = ‘OK’  
puts ‘Received status msg: #{response.message}’  
if(response.message != exp\_msg)  
raise StandardError, “Expected #{exp\_msg} Received  
#{response.message}”  
end

Here there is no nil problem.  
I have been breaking my head and don’t have the slightest clue what is  
happening. Can somebody please shed some light?

---

<div class="post-metadata">

**Author:** ![old\_as\_a\_fossil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/54ee81/32.png) [@old\_as\_a\_fossil](https://www.ruby-forum.com/u/old_as_a_fossil)\
**Post date:** [April 12, 2010, 8:01pm UTC](https://www.ruby-forum.com/t/non-empty-string-complained-to-be-nil-in-equality-check/186792/2 "2010-04-12T20:01:34Z")

</div>

goddammit, i was fooled because the if statement was teh last statement  
in the code. The error didnt happen there at all. This code is a Ruby  
testframework code so it supposed to return a true/false and I was not  
returning, and that has caused the cruelly meaningless error message.  
sorry for wasting everyone’s time.

* * *

---

<div class="post-metadata">

**Author:** ![old\_as\_a\_fossil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/54ee81/32.png) [@old\_as\_a\_fossil](https://www.ruby-forum.com/u/old_as_a_fossil)\
**Post date:** [April 13, 2010, 2:01am UTC](https://www.ruby-forum.com/t/non-empty-string-complained-to-be-nil-in-equality-check/186792/3 "2010-04-13T02:01:37Z")

</div>

Kannan Jay wrote:

> goddammit, i was fooled because the if statement was teh last statement  
> in the code. The error didnt happen there at all. This code is a Ruby  
> testframework code so it supposed to return a true/false and I was not  
> returning, and that has caused the cruelly meaningless error message.  
> sorry for wasting everyone’s time.
> 
> ------------------------------------------------------------------------------It happens. I’m glad you figured it out.

–Alex
