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

S

Sasaki

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
 
H

Harold Hausman

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
 
C

ChrisH

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top