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

**URL:** <https://rubytalk.org/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/36473>\
**Category:** ruby-talk\
**Created:** [27 March 2007 08:30 UTC](https://rubytalk.org/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/36473 "2007-03-27T08:30:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Md\_Ruhul\_Amin](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Md\_Ruhul\_Amin](https://rubytalk.org/u/Md_Ruhul_Amin)\
**Post date:** [27 March 2007 08:30 UTC](https://rubytalk.org/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/36473/1 "2007-03-27T08:30:20Z")

</div>

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

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

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

Sasaki

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Harold\_Hausman](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@Harold\_Hausman](https://rubytalk.org/u/Harold_Hausman)\
**Post date:** [27 March 2007 09:03 UTC](https://rubytalk.org/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/36473/2 "2007-03-27T09:03:20Z")

</div>

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

> **···**
>
> On 3/27/07, Sasaki \<amin@e-sao.co.jp\> wrote:
> 
> > Hi guys,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have a string variable named as 'last\_name'. how can i check  
> > NULL(nil) of this veriable?
> > 
> > as exapmle  
> > if ( empty(last\_name) ) #\*  
> > &nbsp;&nbsp;&nbsp;&nbsp;# code  
> > else  
> > #code  
> > end

---

<div class="post-metadata">

**Author:** ![Chris6](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Chris6](https://rubytalk.org/u/Chris6)\
**Post date:** [27 March 2007 14:10 UTC](https://rubytalk.org/t/help-me-about-nil-check-of-veriable-question-of-a-niw-bie/36473/3 "2007-03-27T14:10:09Z")

</div>

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

> **···**
>
> On Mar 27, 4:30 am, Sasaki \<a...@e-sao.co.jp\> wrote:
> 
> > Hi guys,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have a string variable named as 'last\_name'. how can i check  
> > NULL(nil) of this veriable?
> > 
> > as exapmle  
> > if ( empty(last\_name) ) #\*  
> > &nbsp;&nbsp;&nbsp;&nbsp;# code  
> > else  
> > #code  
> > end
> > 
> > How can I write the syntax in the if statement(\*)?  
> > Please help me.
> > 
> > Sasaki
> > 
> > --  
> > Posted viahttp://www.ruby-forum.com/.
