# Help me about nil check of veriable( question of a niw bie)

**URL:** <https://www.ruby-forum.com/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/90275>\
**Category:** Ruby\
**Created:** [March 27, 2007, 10:30am UTC](https://www.ruby-forum.com/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/90275 "2007-03-27T10:30:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sasaki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@Sasaki](https://www.ruby-forum.com/u/Sasaki)\
**Post date:** [March 27, 2007, 10:30am UTC](https://www.ruby-forum.com/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/90275/1 "2007-03-27T10:30:18Z")

</div>

Hi guys,  
I have a string variable named as ‘last\_name’. how can i check  
NULL(nil) of this veriable?

as exapmle  
if ( empty(last\_name) ) #\*  
# code  
else  
#code  
end

How can I write the syntax in the if statement(\*)?  
Please help me.

Sasaki

---

<div class="post-metadata">

**Author:** ![Sasaki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@Sasaki](https://www.ruby-forum.com/u/Sasaki)\
**Post date:** [March 27, 2007, 11:03am UTC](https://www.ruby-forum.com/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/90275/2 "2007-03-27T11:03:47Z")

</div>

On 3/27/07, Sasaki [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Hi,

I think the .nil? method is the one you’re looking for:

irb(main):001:0\> some\_nil = nil  
=\> nil  
irb(main):002:0\> some\_nil.nil?  
=\> true

Hope that helps,  
-Harold

---

<div class="post-metadata">

**Author:** ![Sasaki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@Sasaki](https://www.ruby-forum.com/u/Sasaki)\
**Post date:** [March 27, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/90275/3 "2007-03-27T16:11:34Z")

</div>

On Mar 27, 4:30 am, Sasaki [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can I write the syntax in the if statement(\*)?  
> Please help me.
> 
> Sasaki
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

Note that an empty string is not nil.  
So if you need to check for nil or empty try:

if last\_name.nil? || last\_name.empty? #…

Cheers  
Chris
