[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

tuhin

3/27/2007 8:30:00 AM

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

--
Posted via http://www.ruby-....

2 Answers

Harold Hausman

3/27/2007 9:03:00 AM

0

On 3/27/07, Sasaki <amin@e-sao.co.jp> wrote:
> 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
>
>

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

Chris Hulan

3/27/2007 2:07:00 PM

0

On Mar 27, 4:30 am, Sasaki <a...@e-sao.co.jp> wrote:
> 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
>
> --
> Posted viahttp://www.ruby-....

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