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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1923672c96592b38c570691547889ee?d=identicon&s=25 Sasaki (Guest)
on 2007-03-27 10:30
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
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 Harold Hausman (Guest)
on 2007-03-27 11:03
(Received via mailing list)
On 3/27/07, Sasaki <amin@e-sao.co.jp> 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
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 ChrisH (Guest)
on 2007-03-27 16:11
(Received via mailing list)
On Mar 27, 4:30 am, Sasaki <a...@e-sao.co.jp> 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
This topic is locked and can not be replied to.